noSvgWithoutTitle
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/a11y/noSvgWithoutTitle
Since: v1.0.0
Enforces the usage of the title
element for the svg
element.
It is not possible to specify the alt
attribute for the svg
as for the img
.
To make svg accessible, the following methods are available:
- provide the
title
element as the first child tosvg
- provide
role="img"
andaria-label
oraria-labelledby
tosvg
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.jsx:1:1 lint/a11y/noSvgWithoutTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Alternative text title element cannot be empty
> 1 │ <svg>foo</svg>
│ ^^^^^
2 │
ℹ For accessibility purposes, SVGs should have an alternative text, provided via title element. If the svg element has role=“img”, you should add the aria-label or aria-labelledby attribute.
code-block.jsx:1:1 lint/a11y/noSvgWithoutTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Alternative text title element cannot be empty
> 1 │ <svg>
│ ^^^^^
2 │ <title></title>
3 │ <circle />
ℹ For accessibility purposes, SVGs should have an alternative text, provided via title element. If the svg element has role=“img”, you should add the aria-label or aria-labelledby attribute.
code-block.jsx:1:1 lint/a11y/noSvgWithoutTitle ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Alternative text title element cannot be empty
> 1 │ <svg>foo</svg>
│ ^^^^^
2 │
ℹ For accessibility purposes, SVGs should have an alternative text, provided via title element. If the svg element has role=“img”, you should add the aria-label or aria-labelledby attribute.
Valid
Section titled ValidAccessibility guidelines
Section titled Accessibility guidelinesDocument Structure – SVG 1.1 (Second Edition) ARIA: img role - Accessibility | MDN Accessible SVGs | CSS-Tricks - CSS-Tricks Contextually Marking up accessible images and SVGs | scottohara.me Accessible SVGs