Definition
The <figcaption>
HTML element is used to provide a caption or description for a media element within a document. It is typically used in conjunction with the <figure>
element, which represents self-contained content, such as images, illustrations, diagrams, or videos.
Here’s an example of how to use the <figcaption>
element:
<figure>
<img src="image.jpg" alt="A beautiful landscape" />
<figcaption>A beautiful landscape captured at sunset.</figcaption>
</figure>
In this example, the <figcaption>
element is used to provide a caption for an image. The <figure>
element wraps both the image and its caption, creating a semantic grouping of the media content and its associated description.
The content within the <figcaption>
element can include any text or other HTML elements that describe or provide context for the media element. It helps visually impaired users understand the content and provides additional information for all users.
The <figcaption>
element can be placed before or after the media element within the <figure>
element, depending on the desired visual presentation and accessibility requirements.
It’s important to note that the <figcaption>
element should be used within the context of the <figure>
element to maintain semantic integrity. Avoid using <figcaption>
without a wrapping <figure>
element.