Links & Media Lesson 18 of 42
HTML Images — Adding Pictures to Your Page
Add images with the img element. Learn src, alt, width and height, image formats (JPG, PNG, SVG, WebP), figure and figcaption, and how to keep pages fast.
A page with only text feels like a textbook without pictures. Images make a page come alive: a school logo, a class photo, a product for sale, a diagram for science class. In HTML, all of these use one small element: <img>.
The img element
<img src="images/mango.jpg" alt="A ripe yellow carabao mango">
<img>is an empty element — no closing tag.src(source) is the path to the image file.alt(alternative text) describes the image in words.
<img src="/img/mango.svg" alt="A ripe yellow carabao mango with a green leaf">
The alt attribute — always include it
The alt text is used when:
- a blind visitor uses a screen reader — the reader says the alt text aloud,
- the image fails to load because of a slow connection or a wrong path — the alt text is shown instead,
- Google indexes your page — alt text helps it understand what the picture is.
<img src="/img/this-file-does-not-exist.jpg" alt="Our Grade 10 class photo at the school gate">
How to write good alt text
- Describe what matters. "Students planting mangrove seedlings during the coastal cleanup" is better than "image1."
- Keep it short. One sentence is usually enough.
- Don't start with "Image of" or "Picture of." Screen readers already announce that it's an image.
- Decorative images get empty alt. If an image is only decoration (like a border swirl), write
alt="". The screen reader will skip it. Don't leavealtout completely.
Width and height
Set width and height in pixels (without "px") to tell the browser how much space the image needs:
<img src="/img/jeepney.svg" alt="A red jeepney" width="160" height="100">
<img src="/img/jeepney.svg" alt="A red jeepney" width="320" height="200">
Why set them even if the image already has a size? While the image is still downloading, the browser can reserve the right space. Without them, the text on the page jumps down when the picture finally appears — very annoying when you're reading on a slow connection.
Image formats
| Format | Best for |
|---|---|
| JPG / JPEG | Photos — small file size, no transparency |
| PNG | Screenshots, logos and images that need a transparent background |
| WebP | Modern format; smaller than JPG and PNG with similar quality |
| SVG | Logos, icons and drawings; stays sharp at any size |
| GIF | Simple short animations (but large files) |
Keep your images light
Many Filipino students and readers browse on mobile data. A single photo straight from a phone camera can be 4–8 MB — that's like downloading a whole song just to see one picture. Before adding photos to your site:
- Resize them. A photo for a web page rarely needs to be wider than 1200 pixels.
- Compress them using a free online image compressor or an app. Aim for under 200 KB per photo.
- Use lazy loading for images further down the page:
loading="lazy". The browser waits until the reader scrolls near them.
<img src="images/field-trip.jpg" alt="Our class at the Rizal Shrine in Calamba" width="800" height="533" loading="lazy">
figure and figcaption — images with captions
When an image needs a visible caption, wrap it in <figure> and add a <figcaption>. This connects the caption to the picture for browsers and screen readers.
<figure>
<img src="/img/halo-halo.svg" alt="A tall glass of halo-halo topped with ube ice cream" width="200" height="240">
<figcaption>Halo-halo: the Filipino summer favorite.</figcaption>
</figure>
Images from other websites
You can put a full URL in src, like src="https://example.com/photo.jpg". But be careful:
- Copyright. Most pictures on the internet belong to someone. Use your own photos, or free-to-use images from sites that clearly allow it, and give credit when asked.
- It can disappear. If the other site deletes or moves the image, your page breaks.
Image as a link
As you saw in the Links lesson, wrapping an image in <a> makes it clickable:
<a href="index.html"><img src="images/logo.png" alt="Home" width="60" height="60"></a>
When an image is the only content of a link, its alt text should describe where the link goes ("Home"), not what the picture looks like.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04