Skip to content

jsx_a11y/media-has-caption Correctness ​

✅ This rule is turned on by default.

What it does ​

Checks if <audio> and <video> elements have a <track> element for captions. This ensures media content is accessible to all users, including those with hearing impairments.

Why is this bad? ​

Without captions, audio and video content is not accessible to users who are deaf or hard of hearing. Captions are also useful for users in noisy environments or where audio is not available.

Example ​

Examples of incorrect code for this rule:

jsx
<audio></audio>
<video></video>

Examples of correct code for this rule:

jsx
<audio><track kind="captions" src="caption_file.vtt" /></audio>
<video><track kind="captions" src="caption_file.vtt" /></video>

How to use ​

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

bash
oxlint --deny jsx-a11y/media-has-caption --jsx-a11y-plugin
json
{
  "plugins": ["jsx-a11y"],
  "rules": {
    "jsx-a11y/media-has-caption": "error"
  }
}

References ​

Released under the MIT License.