HTML figure Tag: Responsive Design & Media Elements

html figure tag

The HTML figure tag links media with a caption. Use it to group an image, diagram, code block, or video with its description. It gives structure and meaning.

Understand the <figure > Tag in HTML

The tag wraps self-contained visual content. It holds one item with a related caption. It tells browsers and readers that the content and caption go together.

This tag is part of HTML5. It adds meaning to how browsers see content. Use it for media and code blocks with labels or notes.

Here is a list of items that show you the Difference Between <figure> and <div> in HTML5:

  • The <figure> means the content and caption are one unit.
  • The <div> means nothing. It only holds content with no meaning.
  • Search engines and screen readers treat <figure> content as a group.

Here is an example:

<figure>
  <img src="cat.jpg" alt="A cat under a tree">
  <figcaption>A cat rests under a tree on a sunny day</figcaption>
</figure>

How it works:

  • <figure> starts the block.
  • <img> loads the image.
  • <figcaption> adds a label to the image.

Use <figure> for content that:

  • Has a caption
  • Stands alone from the main flow
  • Works without breaking the page if removed

Examples include:

  • A chart with a title
  • A photo with a note
  • A code sample with a label

HTML <figure> vs <img> vs <figcaption>

Here’s the structure you need:

<figure>
  <img src="img.jpg" alt="Alt text">
  <figcaption>This caption links to the image above</figcaption>
</figure>

Hierarchy:

  • <figure> is the outer tag
  • <img> or other media goes inside
  • <figcaption> also goes inside, before or after media

How these tags work together:

  • <figure> holds the whole unit
  • <img> adds the media
  • <figcaption> links the caption to the media

This setup shows that all parts belong together.

Here is a table that shows you key differences:

TagPurposeAllowed ContentRole in Semantics
<figure>Group visual + captionAny media + captionStructural
<img>Add imageOnly imagesNone
<figcaption>Add a label to the figure contentText onlySemantic caption

Use <figcaption> Inside <figure>

You can place <figcaption> before or after media.

Caption first:

<figure>
  <figcaption>Tree with fog in winter</figcaption>
  <img src="fog.jpg" alt="Tree covered in fog">
</figure>

Caption after:

<figure>
  <img src="fog.jpg" alt="Tree covered in fog">
  <figcaption>Tree with fog in winter</figcaption>
</figure>

Both options work the same.

Styles of <figure> and <figcaption> with CSS

You can center or left-align captions. Use this format when you write your code:

<figure style="text-align: center;">
  <img src="desk.jpg" alt="Desk with laptop">
  <figcaption>Work desk with laptop</figcaption>
</figure>

You write it like this to avoid layout issues:

Use <figure> with <video>, <canvas>, or <pre>

This tag also wraps other visual elements.

With <video>:

<figure>
  <video controls>
    <source src="clip.mp4" type="video/mp4">
  </video>
  <figcaption>Short video clip of ocean waves</figcaption>
</figure>

With <pre> for code:

<figure>
  <pre><code>console.log('Hello World');</code></pre>
  <figcaption>JavaScript log function example</figcaption>
</figure>

Grouping Related Visual Content:

You can place more than one image inside <figure>.

<figure>
  <img src="one.jpg" alt="First image">
  <img src="two.jpg" alt="Second image">
  <figcaption>First and second image from same trip</figcaption>
</figure>

Browser Support and Compatibility

All modern browsers support <figure> and <figcaption>. That includes:

  • Chrome
  • Firefox
  • Edge
  • Safari
  • Opera

Old browsers treat <figure> as a <div>. You do not need special fallback code.

Examples

Basic Image with Caption:

<figure>
  <img src="mountain.jpg" alt="Snowy mountain peak">
  <figcaption>Snow-covered peak during sunset</figcaption>
</figure>

This shows one image with a clear caption. The <figure> block keeps them together.

Code Sample with Label:

<figure>
  <pre><code><h1>Welcome</h1></code></pre>
  <figcaption>HTML heading example</figcaption>
</figure>

This links the code with its label. You can read and copy both easily.

Video with Caption:

<figure>
  <video controls>
    <source src="forest.mp4" type="video/mp4">
  </video>
  <figcaption>Walk through the forest trail</figcaption>
</figure>

This embeds a video with a matching title. <figure> groups them for clarity.

Two Related Images with One Caption:

<figure>
  <img src="before.jpg" alt="Before cleanup">
  <img src="after.jpg" alt="After cleanup">
  <figcaption>Comparison before and after cleanup</figcaption>
</figure>

This shows two images as one unit. The caption matches both.

Wrapping Up

In this article, you learned what the <figure> tag does and how to use it with <img>, <video>, or <code>. You also saw how to style it and when to use it.

Here is a quick recap:

  • Use <figure> to group content and its label.
  • Place <figcaption> inside <figure>.
  • Use it for images, videos, charts, or code.
  • Style with CSS for layout or alignment.
  • Use it with all browsers.

What is the purpose of the <figure> tag in HTML?

The <figure> tag groups one piece of media with a related <figcaption>. It adds structure and helps screen readers understand the link between content and label.

How does <figure> differ from <div> in HTML?

<div> adds no meaning. It only holds content. <figure> shows that the media and its caption belong together. Search engines and screen readers use this information.

Can I use <figcaption> without <figure>?

No. <figcaption> only works inside <figure>. It has no use on its own and will not label anything without its parent tag.

Does <figure> work with <video> or only with <img>?

Yes. <figure> works with any visual content, including <video>, <canvas>, or <pre>. It only needs a single unit and its matching caption.

Similar Reads

HTML samp Tag: How to Show Sample Program Output

The HTML samp tag shows the result of a computer program or command. It helps readers know which text came…

How to Use HTML div Tag – Examples & Group Content

In this article, you will cover how to use div tag in HTML layout. It offers beginner to advanced code…

HTML autocomplete Attribute: How to Use it with form and input

The form autocomplete attribute in HTML helps users fill out forms faster because it shows them saved input for common…

HTML base Tag: How to Set a Base URL for Links and Resources

Use the <base> tag in HTML to set a single base URL or target for all relative links and resources…

HTML details Tag: How to Toggle Hidden Content

The <details> tag hides content and shows it when needed. It helps organize long pages. The tag shows extra info…

HTML ARIA Attributes for Accessibility

The HTML ARIA attributes help users with disabilities use websites. These attributes describe roles and states for tools. Understand the…

HTML br Tag: Line Breaks

The br tag adds a single line break in HTML. It is an empty tag that does not need a…

The Button Tag in HTML: How it Works with Examples

The HTML button tag creates interactive controls on a web page. You can use this element to trigger actions or…

HTML meta http-equiv Attribute for Web SEO with Examples

This guide explains how to use the HTML meta http-equiv attribute, why it matters for SEO, and how browsers treat…

How to Use sub Tag for Subscript Text in HTML

The sub tag in HTML shows text in subscript form. It places the text slightly below the normal baseline of…

Previous Article

HTML iframe Tag: How to Embed Content with Examples

Next Article

HTML data Tag: Machine-Readable Data

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.