Skip to content
← Back to rules

jsx-a11y/heading-has-content Correctness

What it does ​

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 prop.

Why is this bad? ​

Screen readers alert users to the presence of a heading tag. If the heading is empty or the text cannot be accessed, this could either confuse users or even prevent them from accessing information on the page's structure.

Examples ​

Examples of incorrect code for this rule:

jsx
<h1 />

Examples of correct code for this rule:

jsx
<h1>Foo</h1>

Configuration ​

This rule accepts a configuration object with the following properties:

components ​

type: string[]

default: null

Additional custom component names to treat as heading elements. These will be validated in addition to the standard h1-h6 elements.

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jsx-a11y"],
  "rules": {
    "jsx-a11y/heading-has-content": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jsx-a11y"],
  rules: {
    "jsx-a11y/heading-has-content": "error",
  },
});
bash
oxlint --deny jsx-a11y/heading-has-content --jsx-a11y-plugin

Version ​

This rule was added in v0.0.19.

References ​