HTML <figure> Element

Publish in HTML Tutorial el 24/05/2025 14:28

The <figure> element represents self-contained content, often with a caption (<figcaption>), and is typically referenced as a single unit from the main flow of the document. It can contain images, diagrams, photos, code snippets, or other content that supports the main content but isn't essential for understanding it.


Key characteristics of <figure>:

  • It's a semantic container for content that's referenced from the main content
  • Can include an optional <figcaption> as its first or last child
  • Doesn't have to be only for images - can contain any related content
  • Helps with accessibility by grouping content with its caption


Basic Syntax


Examples of <figure> Usage

Example 1: Basic Image with Caption

The most common use of <figure> is to wrap an image with a caption.

Play Code


Example 2: Code Snippet in Figure

<figure> can also contain code blocks with descriptions.

Play Code


Example 3: Multiple Images in Single Figure

A single <figure> can contain multiple related images.

Play Code


Example 4: Figure with JavaScript Interaction

This example shows how to dynamically change figure content with JavaScript.

Play Code


Example 5: Responsive Figure with CSS

This example demonstrates styling a figure with CSS for responsive design.

Play Code


Tips and Tricks

  • Accessibility: Always include proper alt text for images inside figures
  • Styling: Use CSS to style figures consistently across your site
  • Semantics: Only use <figure> for content that's referenced from the main content
  • Responsiveness: Make sure figures and their content are responsive
  • Caption placement: <figcaption> can be either the first or last child of <figure>


Browser Support

The <figure> element is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It's also supported in Internet Explorer 9 and later.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...