jsx-a11y/alt-text
eslint-plugin-jsx-a11y
No autofixRecommended
eslint.config.js
import jsxA11y from "eslint-plugin-jsx-a11y";
export default [
{
plugins: { "jsx-a11y": jsxA11y },
rules: {
"jsx-a11y/alt-text": "error",
},
},
];Enforce all elements that require alternative text have meaningful information to relay back to end user.
function Foo(props) {
return <img {...props} />
}<img src="foo" />
<img {...props} />
<img {...props} alt /> // Has no value
<img {...props} alt={undefined} /> // Has no value
<img {...props} alt={`${undefined}`} /> // Has no value
<img src="foo" role="presentation" /> // Avoid ARIA if it can be achieved without
<img src="foo" role="none" /> // Avoid ARIA if it can be achieved without
<object {...props} />
<area {...props} />
<input type="image" {...props} />function Foo({ alt, ...props}) {
return <img alt={alt} {...props} />
}
// OR
function Foo(props) {
const {
alt,
...otherProps
} = props;
return <img alt={alt} {...otherProps} />
}<img src="foo" alt="Foo eating a sandwich." />
<img src="foo" alt={"Foo eating a sandwich."} />
<img src="foo" alt={altText} />
<img src="foo" alt={`${person} smiling`} />
<img src="foo" alt="" />
<object aria-label="foo" />
<object aria-labelledby="id1" />
<object>Meaningful description</object>
<object title="An object" />
<area aria-label="foo" />
<area aria-labelledby="id1" />
<area alt="This is descriptive!" />
<input type="image" alt="This is descriptive!" />
<input type="image" aria-label="foo" />
<input type="image" aria-labelledby="id1" />Examples from the ESLint documentation.
jsx-a11y/alt-text
eslint-plugin-jsx-a11y
import jsxA11y from "eslint-plugin-jsx-a11y";
export default [
{
plugins: { "jsx-a11y": jsxA11y },
rules: {
"jsx-a11y/alt-text": "error",
},
},
];jsx-a11y/alt-text
jsx-a11y plugin · correctness
{
"plugins": [
"jsx-a11y"
],
"rules": {
"jsx-a11y/alt-text": "error"
}
}a11y/useAltText
a11y · since 1.0.0
{
"linter": {
"rules": {
"a11y": {
"useAltText": "error"
}
}
}
}Enforce ARIA state and property values are valid.
Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes.
Enforce that elements with ARIA roles must have all required attributes for that role.
Enforce that elements with explicit or implicit roles defined contain only aria-* properties supported by that role.
Enforce all anchors to contain accessible content.