jsx-a11y/heading-has-content

Require headings to have content that a screen reader can read

Also called jsx_a11y/heading-has-content

People who use a screen reader move through a page by its headings. An empty h1 to h6, or one with only hidden content, is a stop in that list with nothing to read.

Text, an expression and a visible element count as content. So do the children and dangerouslySetInnerHTML props. A heading that's hidden itself with aria-hidden isn't checked.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"jsx-a11y/heading-has-content" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"jsx-a11y/heading-has-content" = ["error", {
  components = [], # list of strings
}]

Examples#

example.jsx2 problems
const title = <h1 className="hero" />;
const section = <h2><span aria-hidden>Pricing</span></h2>;
example.jsxNo problems
const title = <h1 className="hero">{page.title}</h1>;
const section = <h2><span>Pricing</span></h2>;

Options#

OptionDefaultWhat it does
components[]Components to check like h1 to h6.
example.jsxwith { "components": ["Heading"] }1 problem
const title = <Heading level={1} />;