HTML <figcaption> Element

Publish in HTML Tutorial el 23/05/2025 23:11

The <figcaption> HTML element represents a caption or legend describing the rest of the contents of its parent <figure> element. It provides semantic meaning to images, diagrams, illustrations, code snippets, or other media content by allowing you to associate a visible description.


Key characteristics of <figcaption>:

  • Must be placed inside a <figure> element
  • Can be the first or last child of the <figure>
  • Improves accessibility by providing context
  • Helps with SEO by associating text with media


Basic Syntax

Here's the basic structure of how <figcaption> is used:


Examples

Example 1: Basic Image with Caption

A simple image with a descriptive caption below it:

Play Code


Example 2: Code Snippet with Caption

Showing a code block with an explanatory caption:

Play Code


Example 3: Multiple Images with Group Caption

Grouping several images under one caption:

Play Code


Example 4: Dynamic Caption with JavaScript

Changing the caption text using JavaScript:

Play Code


Example 5: Interactive Figure with JavaScript

Creating an interactive figure that responds to user actions:

Play Code


Tips and Tricks

  • Accessibility: Always include proper alt text for images before adding a figcaption.
  • Positioning: The figcaption can be placed either before or after the content in the figure.
  • Styling: Use CSS to style your figcaptions consistently across your site.
  • SEO: Include relevant keywords in your captions when appropriate.
  • Length: Keep captions concise but descriptive enough to be useful.
  • Numbering: For academic or technical content, consider numbering your figures.


Browser Support

The <figcaption> 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 ...