Chapter 22 | figure
and figcaption
In this chapter we conclude our exploration of grouping elements by looking at the figure
and figcaption
elements.
figure
The figure
element is much like the article
element in that it should be used as a container for content that is self-contained. The figure
element has an implicit ARIA role of figure
. While this is true, if the figure
is used without a figcaption
you can assign any ARIA role to the figure
element. Again, if you find yourself wanting, or needing, to do that, perhaps a different element will be more appropriate.
One of the benefits of the figure
role for users of assistive technologies is that the ARIA specification states that assistive technologies should enable users to quickly navigate to figures. This means that screen readers, for example, will offer a means to jump to the various figure
elements on the page without having to tab through all the content on the page.
Any flow content is allowed to be children of the figure
element, but the element is most commonly used to contain graphical documents such as maps, graphs, images, code snippets, or example text. For example:
|
|
Or for an image:
|
|
Live Codepen - The figure
element
See the live example on Codepen.io
The following is a useful quote from the HTML specification that is good to keep in mind when using the figure
element.
When a figure is referred to from the main content of the document by identifying it by its caption (e.g., by figure number), it enables such content to be easily moved away from that primary content, e.g., to the side of the page, to dedicated pages, or to an appendix, without affecting the flow of the document.
If a figure element is referenced by its relative position, e.g., “in the photograph above” or “as the next figure shows”, then moving the figure would disrupt the page’s meaning. Authors are encouraged to consider using labels to refer to figures, rather than using such relative references, so that the page can easily be restyled without affecting the page’s meaning.
See the quote in its original context here.
figcaption
The figcaption
element goes hand in hand with the figure
element as a means to provide a short concise description of the content of its parent figure
. It is important to note that the figcaption
does not replace the need for alt
text when used with an image but, that it is more complimentary, for example:
|
|
Live Codepen - The figcaption
element
See the live example on Codepen.io
The figcaption
can be placed before or after the main figure
content. As can be seen in the above example, the figcaption
can also contain other flow content elements.
This concludes our look at the grouping elements of HTML. In the next chapter we will start looking at text level semantics.