Headings
Heading Structure
Headings play a pivotal role in web accessibility. They help in organizing content hierarchically, making it easier for screen readers and other assistive technologies to navigate through the document. This is in line with WCAG 2.1 guideline 1.3.1 (Info and Relationships), which emphasizes that information and relationships conveyed through presentation can be programmatically determined. Similarly, the French RGAA criterion 9.1 checks if sections of content are structured using appropriate headings.
A well-structured document with clear headings allows users to understand the layout and easily navigate through sections.
For instance, using <h1> for the main title and <h2> for subsections maintains a clear hierarchy, as demonstrated in our React component example:
// DO
const AccessibleArticleComponent = () => {
return (
<article>
<h1>Main Article Title</h1>
<section>
<h2>Section Title</h2>
<p>Content for this section...</p>
</section>
<section>
<h2>Another Section Title</h2>
<p>More content for another section...</p>
</section>
</article>
);
};
// Don't
const NonAccessibleArticleComponent = () => {
return (
<article>
<div>Main Article Title</div>
<div>Section Title</div>
<p>Content for this section...</p>
<div>Another Section Title</div>
<p>More content for another section...</p>
</article>
);
};
Headings with Murray
Do
Main Article Title
Section Title
Content for this section...
Another Section Title
More content for another section...
Don't
Main Article Title Section Title Content for this section... Another Section Title More content for another section...
Documentation: Heading
Tricky cases
As we tend to split our code in components, sometime the heading level depens on the context. In that case, you can skip heading levels, but be sure the page level hierarchy stays consistent. You need to keep incresing the heading level, even if you skip some levels.
Allowed. Heading levels stay constitent:
<section>
<h2>Article list</h2>
<!-- articles are components that will always render a h4 -->
<article>
<h4>Article Title</h4>
<p>This is a caption</p>
</article>
<article>
<h4>Another Article Title</h4>
<p>This is another caption</p>
</article>
</section>
Not Allowed. Heading levels consistency is brooken:
<section>
<h2>Article list</h2>
<article>
<h4>Article Title</h4>
<p>This is a caption</p>
</article>
<article>
<!-- Using a h5 is not consistent with the h4 above. Both are article titles. They should be either a h4 or h5 -->
<h5>Another Article Title</h5>
<p>This is another caption</p>
</article>
</section>
- ➡️ Keep in mind that the heading level is relative to the page, not to the component.
- ➡️ Those cases should remain exceptional.