caption

Role for a visible caption for a table, grid, and standalone graphic content with the role figure.

Time to read: less than 5 min

Briefly

Document structure role from WAI-ARIA for a visible caption for a table, regular or tree grid, and standalone graphic content.

In HTML, this role is automatically present on <caption>.

How to Write

Assign the tag role="caption", preferably to <div> or <span>. However, for a <table> it is best to use <caption> primarily, and for a <figure><figcaption>.

Elements with caption can describe only some elements and ARIA roles:

The caption element must be nested within containers with the roles figure, table, grid, and treegrid. For table, grid, and treegrid, the description should be the first child element, and for figure — either the first or the last.

To link the caption to the role caption and the element it relates to, set aria-labelledby on the parent element and id with the same value for the caption. If you want to add additional detailed description, it can also be nested within the caption and linked to the main element using aria-describedby.

For elements with the role caption, all global ARIA attributes can be used.