Figure and Figcaption
What you'll learn: How to semantically group images with their captions using <figure> and <figcaption> elements.
Why These Elements Matter
You've already learned how to add images with <img> and alt text. But what happens when an image needs a visible caption? You could just put an image and a paragraph next to each other, but HTML gives us a better, more meaningful way: the <figure> and <figcaption> elements.
The Core Idea
Think of <figure> like a frame around a museum painting — it groups the artwork with its descriptive placard. The <figure> element wraps around content that is self-contained but referenced from the main content (like an illustration, diagram, photo, or code snippet). The <figcaption> element provides a caption or legend for that content.
<figure>
<img src="sunset.jpg" alt="Orange and pink sunset over calm water">
<figcaption>Sunset at Malibu Beach, July 2024</figcaption>
</figure>
Key Points
<figure>is the container for the image and caption together<figcaption>goes inside the<figure>and can appear before or after the image- The
altattribute still describes the image itself; the caption provides context, credit, or additional information - You can have a
<figure>without a<figcaption>, but you can't have<figcaption>outside a<figure>
This semantic grouping tells browsers, search engines, and assistive technologies that the caption and image are connected — much clearer than just placing them side-by-side with generic elements.
Key Takeaway: Use <figure> and <figcaption> to semantically group images with their captions, creating a meaningful relationship between visual content and its description.