HTML `<figcaption>` Element: Adding Captions to Figures for Enhanced Accessibility
Learn how to use the HTML `<figcaption>` element to add descriptive captions to figures (images, illustrations, diagrams, code snippets). This tutorial explains its placement within the `
Using the HTML <figcaption> Element for Captions
What is the <figcaption> Element?
The HTML <figcaption>
element (figure caption) defines a caption for a <figure>
element. A <figure>
element typically contains an image, illustration, diagram, code snippet, or other self-contained content. The <figcaption>
provides a descriptive caption for that content, improving readability and accessibility. The <figcaption>
element can be placed either before or after the content within the <figure>
element.
Example:
HTML
<figure>
<img src="image.jpg" alt="Trulli in Italy">
<figcaption>Fig. 1 - Trulli, Puglia, Italy</figcaption>
</figure>
Browser Support
The <figcaption>
element is widely supported by modern browsers. Here's a table showing the first version of each browser to fully support it:
Browser | Version |
---|---|
Chrome | 8.0 |
Firefox | 9.0 |
Internet Explorer | 10 |
Safari | 5.1 |
Edge | 11.0 |
Styling <figure> and <figcaption> with CSS
You can style both the <figure>
and <figcaption>
elements using CSS to customize their appearance and integration within your page layout.
Example:
CSS
figure {
margin: 20px;
border: 1px solid #ccc;
padding: 10px;
}
figcaption {
text-align: center;
font-style: italic;
}