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 / Explain Forms with fieldset, legend, and autocomplete

HTML Tutorial / Explain Forms with fieldset, legend, and autocomplete

Group related controls with fieldset and legend, and use suitable autocomplete tokens to describe the purpose of input fields.

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 / Use textarea, select, option, and button

HTML Tutorial / Use textarea, select, option, and button

Create multi-line fields, selection lists, and form buttons while understanding initial values, submitted values, and reset behavior.

HTML Tutorial / Add Placeholder Text to Form Fields

HTML Tutorial / Add Placeholder Text to Form Fields

Learn how to add placeholder hints to HTML input and textarea fields without confusing them with labels or initial values. Includes a complete form example, required-field checks, and an explanation of empty values in submitted data.

HTML Tutorial / Connect Labels and Inputs Correctly

HTML Tutorial / Connect Labels and Inputs Correctly

Connect labels to inputs with for and id, distinguish id from submitted name, and learn why placeholder text cannot replace a label.

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 / Text Semantics: Emphasis, Quotations, Abbreviations, and Code

HTML Tutorial / Text Semantics: Emphasis, Quotations, Abbreviations, and Code

Learn when to use HTML em, strong, q, blockquote, abbr, code, and kbd. Examples show how each element conveys meaning rather than just changing the appearance of text.

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 / Choose Input Types for Email, Numbers, Dates, and Choices

HTML Tutorial / Choose Input Types for Email, Numbers, Dates, and Choices

Choose input types based on the value being collected and understand how checkboxes and radio groups behave when submitted.