| JPEG | Best for photographs. Lossy compression — small file size, slight quality loss. Not good for logos or sharp edges. |
|---|---|
| PNG | Best for graphics, logos, screenshots. Lossless, full color. Supports transparency. Use instead of GIF for most things. |
| GIF | Only 256 colors. Still used for simple animations. Otherwise PNG is better. |
| WebP | Modern format — smaller than JPEG/PNG at similar quality. Supported by all current browsers. |
| SVG | Vector format — scales to any size without pixelation. Good for icons and logos. |
The <img> tag is a void element — no closing tag.
Use the src attribute to point to the image file:
<img src="photo.jpg"> <!-- same folder --> <img src="./photo.jpg"> <!-- same folder --> <img src="images/photo.jpg"> <!-- subfolder --> <img src="../photo.jpg"> <!-- one folder up --> <img src="https://example.com/photo.jpg"> <!-- linked from web -->
Every <img> should have an alt attribute describing what the image shows:
<img src="salad.jpg" alt="Fresh multi-bean salad in a white bowl">
Why it matters:
Use the <table> tag to display data in rows and columns.
| 2001 | 2002 | 2003 | |
|---|---|---|---|
| First-Year | 355 | 314 | 301 |
| Transfers | 43 | 33 | 30 |
<table>
<caption><strong>NEW STUDENTS (FALL)</strong></caption>
<tr><td></td> <th>2001</th> <th>2002</th> <th>2003</th></tr>
<tr><th>First-Year</th> <td>355</td> <td>314</td> <td>301</td></tr>
<tr><th>Transfers</th> <td>43</td> <td>33</td> <td>30</td></tr>
</table>
A table is built from three nested tags:
<tr> — table row (a horizontal strip)<th> — table header cell (bold, centered by default)<td> — table data cell (regular content)<caption> — a title above the tableYouTube generates the HTML for you — you just copy and paste it.
<iframe> code it gives you<iframe> — a window inside your page that loads another web page (the YouTube player). You don't need to understand all of it yet. Make sure the URL starts with https://.
file:// address in the browser), the video may show a YouTube "Error 153" message instead of playing. YouTube checks that the page has a real web address, and a local file does not have one. View your page through a local server instead, for example VS Code's Live Server extension, and the video will load normally.
Live Server starts a small local server on your own machine and opens your page in a real browser tab with a real address, like http://127.0.0.1:5500, instead of file://. This is what fixes the YouTube "Error 153" problem from the previous slide.
⇧⌘X on Mac, Ctrl+Shift+X on Windows)
Several similarly named extensions show up. Install the one by Ritwick Dey (top result above), not one of the others.
⌘L ⌘O on Mac)http://127.0.0.1:5500/html_04.html. Anything that needs a real server, like the YouTube embed, now works.Instead of embedding from YouTube, you can host a video file yourself using the HTML5 <video> tag:
<video src="my_video.mp4" controls>
<p>Your browser doesn't support HTML video.</p>
</video>
Useful attributes:
controls — shows play/pause/volume controlsautoplay — starts playing immediately (use sparingly)loop — repeats the videomuted — starts muted (required for autoplay in most browsers)width="560" — sets the display widthOpen your recipe page from last class. Add the following (no <pre> tag anywhere (it will break later CSS and JavaScript exercises).)
src="filename.jpg"https://... URL as the srcalt attribute<table>
| Calories | Protein | Fat | |
|---|---|---|---|
| Salad | 180 | 6g | 9g |
| Dressing | 120 | 1g | 12g |
<pre> tags in your file