Figure and figcaption in HTML are used to group self-contained content with an optional caption. The most common use is an image with a caption, but the <figure> element is not limited to images. It can also wrap diagrams, illustrations, code examples, charts, videos, tables, or any content that can stand on its own.
The <figcaption> element provides a visible caption for the figure. This caption explains what the figure represents, why it matters, or how the reader should understand it. Together, these two tags make media content more semantic and easier to understand.
In this article, we will understand the figure tag, the figcaption tag, correct syntax, caption placement, image captions, accessibility, SEO value, common mistakes, and best practices for using figure and figcaption in HTML.
What is the figure Tag in HTML?
The <figure> tag represents self-contained content. Self-contained means the content can be moved away from the main flow without breaking the meaning of the surrounding text. For example, a diagram explaining a circuit, a screenshot in a tutorial, or a code example can often be treated as a figure.
A figure is not just a random wrapper like <div>. It gives semantic meaning. It tells the browser, assistive technology, and future developers that the grouped content is a distinct item related to the document.
<figure>
<img src="html-layout.png" alt="Basic HTML document layout">
</figure>Use figure when the content is a meaningful standalone item, not merely because you need a container for styling.
What is the figcaption Tag in HTML?
The <figcaption> tag defines a caption for the nearest parent <figure>. It can appear as the first child or the last child inside the figure. The caption should describe or explain the figure in a way that helps the reader.
<figure>
<img src="html-elements.png" alt="Common HTML elements shown as a diagram">
<figcaption>Common HTML elements used to structure a web page.</figcaption>
</figure>The caption is visible on the page. It is different from the image alt text. Alt text is fallback and accessibility text for the image itself. Figcaption is a visible explanation for all users.
| Element | Purpose | Common Content |
|---|---|---|
<figure> | Groups standalone content | Images, diagrams, videos, code examples, charts. |
<figcaption> | Adds a caption to a figure | Visible explanation or label for the figure. |
<img> | Embeds an image | Photo, screenshot, diagram, icon, illustration. |
Caption Before or After the Content
A <figcaption> can be placed before or after the main figure content. Most articles place it after the image or diagram because that feels natural to readers. Placing it before can work when the caption acts like a title or label before the content.
<figure>
<figcaption>Figure 1: Basic HTML page structure.</figcaption>
<img src="page-structure.png" alt="HTML page structure diagram">
</figure>Both placements are valid. The key is consistency. If your website places captions below images, follow that style across similar posts. In tutorials, a caption below the visual is usually easiest to scan.
Using figure for More than Images
The figure element can wrap more than images. You can use it for a code listing, chart, table, video, quote, or diagram when the content has its own caption or standalone meaning. This makes the markup more expressive than using only a generic div.
<figure>
<pre><code>console.log("Hello HTML");</code></pre>
<figcaption>Example 1: A simple JavaScript output statement.</figcaption>
</figure>This does not mean every code block must be a figure. Use it when a caption genuinely helps. If the code is already introduced clearly by surrounding text, a normal code block may be enough.
figure vs div in HTML
A <div> is a generic container with no specific meaning. A <figure> has semantic meaning. If the content is a standalone visual or example with a caption, <figure> is usually better. If you only need a wrapper for layout, <div> may be more appropriate.
| Use Case | Better Element | Reason |
|---|---|---|
| Image with visible caption | <figure> | The image and caption form a semantic unit. |
| Styling wrapper around several cards | <div> | The wrapper is only for layout. |
| Code example with label | <figure> | The example can stand alone and has a caption. |
| Random group of text blocks | <div> | No standalone figure meaning exists. |
Accessibility and figcaption
Figcaption improves understanding because it provides visible context. However, it does not replace proper alt text for images. If the image is meaningful, write useful alt text. If the caption already explains the image fully, the alt text can be shorter, but it should not be missing unless the image is decorative.
Avoid writing the exact same long sentence in both alt and figcaption. That can become repetitive for assistive technology users. A good pattern is to let alt text describe the image and let figcaption explain the figure's role in the article.
Quick accessibility rule
Use alt text for the image itself and figcaption for the visible explanation around the figure. They can support each other, but they are not the same thing.
Best Practices for figure and figcaption
- Use
<figure>for standalone images, diagrams, screenshots, videos, charts, or examples. - Use
<figcaption>when a visible caption improves understanding. - Do not use
<figure>only as a styling wrapper. - Keep captions short, clear, and connected to the content.
- Write alt text separately from captions when the image is meaningful.
- Be consistent about caption placement across similar articles.
When figure Makes Content Better
The figure element is most useful when the reader may want to understand a visual or example as a separate unit. In a technical tutorial, a circuit diagram, HTML page structure image, browser screenshot, code output screenshot, or comparison chart often deserves figure markup because it supports the explanation directly.
Figure markup also helps future maintenance. When another editor reads the HTML source, a figure tells them that the grouped content belongs together. If the image changes, the caption may also need to change. If the caption is moved, the meaning of the visual may become weaker. This relationship is clearer with figure than with a plain div.
Writing Good Captions
A good caption should not merely repeat the filename. It should explain the value of the figure. For example, Screenshot 1 is weak. Browser output of a basic HTML form is better because it tells the reader what they are seeing.
Captions can also add context that does not belong in alt text. If a diagram compares two approaches, the caption can summarize the comparison. If a screenshot shows a final result, the caption can mention the result. Keep captions direct and avoid turning them into long paragraphs unless the figure genuinely needs explanation.
SEO Notes for figure and figcaption
Search engines can read surrounding text around images, including captions. A clear figcaption can help explain what a visual represents. This does not mean captions should be stuffed with keywords. Instead, write captions that help humans, and the SEO value follows naturally.
For tutorial websites, captions are especially useful because they connect images to concepts. A caption such as Basic structure of an HTML document is more useful than image one. It gives readers and crawlers a stronger signal about the purpose of the visual.
Real World Examples of figure Usage
In documentation, figure is commonly used for architecture diagrams, terminal screenshots, output previews, circuit diagrams, UI screenshots, and charts. These pieces of content often support the main explanation but can also be understood as separate references. That makes them good candidates for figure markup.
In educational posts, figure and figcaption can make examples feel cleaner. Instead of writing a paragraph that says “the image below shows the output”, the caption can directly label the output. This keeps the article easier to scan and helps readers connect visuals with the correct explanation.
Maintaining Figures in Large Articles
When an article has many visuals, consistent figure captions make maintenance easier. If you later replace an image, you can quickly check whether the caption still matches the new visual. If a tutorial changes, captions can reveal outdated screenshots faster than unlabeled images.
For large technical posts, short captions also help reviewers. A reviewer can skim captions and understand the flow of examples without reading every paragraph. That makes figure and figcaption useful not only for final readers, but also for editing and long-term content quality.
Common Mistakes
A common mistake is using <figcaption> outside a <figure>. The figcaption element is meant to caption a figure, so it should be inside the figure element. Another mistake is using figure for every image automatically. Some images are decorative or inline with text and do not need figure markup.
Another mistake is treating figcaption as a replacement for alt text. Captions and alt text solve different problems. If the image fails to load, the alt text is the fallback. If the image loads normally, the caption gives visible context.
FAQs
What is figure in HTML? 3
The <figure> element groups self-contained content such as an image, diagram, code example, table, video, or chart.
What is figcaption in HTML? 3
The <figcaption> element adds a visible caption to a parent <figure> element.
Can figcaption come before an image? 3
Yes. A figcaption can be the first or last child inside a figure. Most articles place it after the image, but both positions are valid.
Does figcaption replace alt text? 3
No. Alt text describes the image for fallback and accessibility. Figcaption is visible caption text for the figure.
Can figure be used without figcaption? 3
Yes. A figure can exist without figcaption, but if a visible caption would help users understand the content, add one.
Continue learning HTML in order
Follow the topic sequence with the previous and next lesson.