AD JB Toolbox 01 EN

HTML Tutorial / Group Images and Captions with figure and figcaption

figure groups self-contained content such as an image, chart, or code sample, and figcaption gives that figure a visible caption. Not every image needs these elements. Use them when the content and its explanation belong together as one unit.

Keep an image and caption together

A travel photo and its location or context can form one figure. Put figcaption as the first or last child of figure.

<figure>
  <img src="lake.webp"
       alt="A mountain ridge beyond a calm lake"
       width="960" height="540">
  <figcaption>The lake in the early morning</figcaption>
</figure>

Place lake.webp beside the HTML file and open the page. The caption appears below the image. To place the caption before it, move figcaption before img. Adjust size and spacing with CSS. If the file is in an images folder, use src="images/lake.webp". The width and height should preserve the real image's aspect ratio and help reserve space while it loads.

Alt text and captions do different jobs

The alt text conveys the image's information or function when the image cannot be perceived. The visible figcaption supplies a title, source, or context for everyone. Repeating exactly the same sentence in both can create redundant reading. In the example, the alt text describes what is visible, while the caption gives the time of day.

For a purely decorative image, consider alt="", but first check that important information is available elsewhere. A chart needs its main trend or result conveyed, not merely the phrase “bar chart.” If its data requires a longer explanation, provide that in nearby text or a table and let the alt text lead readers to it. The W3C WAI alt-text decision tree helps with this choice.

When can you omit figure?

An ordinary image within the flow of a paragraph does not need figure if it has no separate caption or reference. A diagram discussed as “the following figure,” or a code sample with a caption, is a stronger candidate. A figure can contain more than an image. See the MDN figure reference for its content model.

If the result looks wrong

Browsers may add default margins around figure. Check its CSS margin before changing the HTML structure. If the image is missing, check the filename and relative path. If the caption is missing, verify that figcaption is inside figure and the closing tags are present. A caption does not automatically provide appropriate alt text; review both separately.

More in This Category
HTML Tutorial / Images: img, Alt Text, and Dimensions

HTML Tutorial / Images: img, Alt Text, and Dimensions

Add an image with HTML img, write useful alternative text, and set width and height correctly. A downloadable example helps you test file paths and sizing.

HTML Tutorial / Headings and Paragraphs

HTML Tutorial / Headings and Paragraphs

Learn when to use h1–h6 headings, p paragraphs, and br line breaks in HTML. Examples show document hierarchy, browser output, and common mistakes.

HTML Tutorial / Links: Paths, Page Fragments, and Email

HTML Tutorial / Links: Paths, Page Fragments, and Email

Create HTML links with absolute or relative URLs, jump to a document fragment, and add email, new-tab, or download links. Learn what to verify before publishing.

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

Make table headings and data relationships clear with caption, th, and scope, and learn when colspan or rowspan makes a table harder to read.

HTML Tutorial / When to Use div and span

HTML Tutorial / When to Use div and span

Understand the structural difference between div and span, style only the content you need, and choose semantic elements when they better describe the content.

HTML Tutorial / Divide a Page with Semantic Elements

HTML Tutorial / Divide a Page with Semantic Elements

Learn when to use header, nav, main, article, section, aside, and footer, then build a complete page whose regions and in-page links work together.

HTML Tutorial / Table Basics: table, tr, th, and td

HTML Tutorial / Table Basics: table, tr, th, and td

Build a basic HTML data table with rows and header or data cells, then organize its headings and body without using tables for page layout.

HTML Tutorial / Group Images and Captions with figure and figcaption

HTML Tutorial / Group Images and Captions with figure and figcaption

Use figure and figcaption to keep an image and its visible explanation together, and distinguish captions from image alt text.

HTML Tutorial / Lists: ul, ol, dl, and Nested Lists

HTML Tutorial / Lists: ul, ol, dl, and Nested Lists

Choose the right HTML list for ordered items, unordered items, and name–description pairs. Try a complete example, custom numbering, and correctly nested lists.

HTML Tutorial / Responsive Images: srcset, sizes, and picture

HTML Tutorial / Responsive Images: srcset, sizes, and picture

Offer image resolutions with srcset and sizes, and switch crops with picture. Downloadable files let you test the examples in a browser.