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 Boolean Attributes with Examples

HTML Boolean attributes control the behavior of elements and do not need a value. These attributes simplify logic and reduce…

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…

HTML Syntax for Beginners: How it Works with Examples

HTML syntax shows how tags and attributes go together. It gives browsers the rules to read and display a page.…

HTML Heading Elements: Understanding h1 to h6 with Examples

The heading elements define a content structure in HTML. Use <h1> to <h6> to show levels. <h1> means the main…

HTML style Tag: Inline CSS

The style tag in HTML defines CSS inside a web page. Click to see how it works with syntax and…

HTML wbr Tag: Word Break Opportunities

The <wbr> tag in HTML helps the browser decide where it can break a word. It does not force a…

HTML Introduction for Beginners from Scratch

HTML is the main content for every web page. It helps you structure text, links, and media. You can build…

HTML5 New Elements with Examples

HTML5 gave the web new elements that describe content with more meaning. Developers now use these elements to build pages…

HTML List Tag: Understand the ul, ol, and dl Lists

HTML has three main list tags: <ul>, <ol>, and <dl>. Each one shows a different kind of group. In this…

HTML time Tag: Representing Dates and Times

The HTML time Tag marks time values in a document. Use it to show dates or times that machines and…

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.