useHeadingContent (HTML)
Summary
Section titled “Summary”- Rule available since:
v2.5.0 - Diagnostic Category:
lint/a11y/useHeadingContent - This rule is recommended, meaning it is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Inspired from
jsx-a11y/heading-has-content - Same as
@html-eslint/no-empty-headings
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "a11y": { "useHeadingContent": "error" } } }}Description
Section titled “Description”Enforce that heading elements (h1, h2, etc.) have content and that the content is
accessible to screen readers.
Accessible means that it is not hidden using the aria-hidden attribute.
All headings on a page should have content that is accessible to screen readers
to convey meaningful structure and enable navigation for assistive technology users.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<h1></h1>code-block.html:1:1 lint/a11y/useHeadingContent ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide screen reader accessible content when using heading elements.
> 1 │ <h1></h1>
│ ^^^^^^^^^
2 │
ℹ All headings on a page should have content that is accessible to screen readers.
<h1 aria-hidden="true">invisible content</h1>code-block.html:1:1 lint/a11y/useHeadingContent ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide screen reader accessible content when using heading elements.
> 1 │ <h1 aria-hidden="true">invisible content</h1>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ All headings on a page should have content that is accessible to screen readers.
<h1><span aria-hidden="true">hidden</span></h1>code-block.html:1:1 lint/a11y/useHeadingContent ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Provide screen reader accessible content when using heading elements.
> 1 │ <h1><span aria-hidden="true">hidden</span></h1>
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ All headings on a page should have content that is accessible to screen readers.
<h1>heading</h1><h1 aria-label="Screen reader content"></h1><h1><span aria-hidden="true">hidden</span> visible content</h1>Accessibility guidelines
Section titled “Accessibility guidelines”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.