alt-text
Configuration
Rule Details
Enforces that elements that require alternative text — <img>, <object>,
<area>, and <input type="image"> — have meaningful information available
to screen readers.
The rule reports problems in these scenarios:
- An
<img>has noaltprop, noaria-label, and noaria-labelledby, and is not marked with a presentational role. - An
<img>has analtprop, but the value isundefined,false, the literal string"false", or another expression that statically evaluates to falsy. - An
<img>declaresaria-labeloraria-labelledbybut its value is empty or explicitlyundefined(the rule still reports because that attribute can't actually serve as the text alternative). - An
<img>usesrole="presentation"orrole="none"instead of writingalt=""for a decorative image. - An
<object>has no inner accessible content, notitle, noaria-label, and noaria-labelledby. - An
<area>or<input type="image">has noalt, noaria-label, and noaria-labelledby.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
elements
Type: string[]. Default:
["img", "object", "area", "input[type=\"image\"]"].
Whitelist of DOM elements the rule should validate. Set this to a subset to
disable the check for specific elements, or to [] to disable the rule
entirely.
Per-element custom-component lists
Each element key (img, object, area, input[type="image"]) accepts an
array of component names. Listed components are validated alongside the
matching DOM element — for example, "img": ["Thumbnail", "Image"] makes
<Thumbnail /> and <Image /> follow the same alt-text rules as <img>.
Examples of incorrect code with { "img": ["Image"] }:
Examples of correct code with { "img": ["Image"] }:
Settings
The rule reads two settings['jsx-a11y'] keys when resolving the effective
element type for a JSX tag:
polymorphicPropName— name of a polymorphic prop (e.g."as") that remaps the element type. WithpolymorphicPropName: "as",<SomeComponent as="img" />is treated as<img />.polymorphicAllowList—string[]restricting which raw component names may be remapped via the polymorphic prop. When omitted, every component may be remapped.components— a{ ComponentName: "html-element" }map. With{ "Input": "input" },<Input type="image" />is treated as<input type="image" />.
These mirror the upstream eslint-plugin-jsx-a11y settings exactly.