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>Directives that render the heading text are treated as content: set:html
and set:text in Astro files, v-html and v-text in Vue files. Headings
that use them are not reported.
<h1 set:html={heading} /><template><h1 v-text="heading"></h1></template>Accessibility guidelines
Section titled βAccessibility guidelinesβRelated links
Section titled βRelated linksβCopyright (c) 2023-present Biome Developers and Contributors.