Build an image gallery
Task
Create a simple gallery of three images, each with a meaningful alt attribute and a caption using <figure>/<figcaption>.
Requirements
- Each image is wrapped in a <figure>
- Each <figure> contains a <figcaption> with a caption
- Every <img> has a meaningful alt attribute (not empty, not "image")
- At least 3 images are used
Starter code
<div class="gallery">
</div>
▶ Open in HTML Editor Hints
- alt should describe what's in the image, not just repeat the file name.
- figcaption is written inside figure, either before or after the img.
Show solution
<div class="gallery">
<figure>
<img src="cat.jpg" alt="Ginger cat sleeping on a windowsill">
<figcaption>House cat</figcaption>
</figure>
<figure>
<img src="mountains.jpg" alt="Mountain range at sunset">
<figcaption>Sunset over the mountains</figcaption>
</figure>
<figure>
<img src="city.jpg" alt="City at night with lit-up buildings">
<figcaption>City in the evening</figcaption>
</figure>
</div>
Related tools
HTML Editor Online
Write HTML with syntax highlighting and line numbers, see a live preview, format or minify it, and open or save .html files — all in your browser.
Images
Lesson 5: how to add images with <img>, what the src and alt attributes do and why alt matters for accessibility. Example, task and a gallery exercise.
The <img> tag
The src, alt, loading, and srcset attributes of the <img> tag, with examples.