src/content/docs/linter/rules/no-svg-without-title.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JSX and TSX" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/a11y/noSvgWithoutTitle`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). ## How to configure ```json title="biome.json" { "linter": { "rules": { "a11y": { "noSvgWithoutTitle": "error" } } } }## Description
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 to `svg`
- provide `role="img"` and `aria-label` or `aria-labelledby` to `svg`
## Examples
### Invalid
```jsx
<svg>foo</svg>
<svg>
<title></title>
<circle />
</svg>
<svg>foo</svg>
<svg>
<rect />
<rect />
<g>
<title>foo</title>
<circle />
<circle />
</g>
</svg>
<svg role="graphics-symbol"><rect /></svg>
<svg>
<title>Pass</title>
<circle />
</svg>
<svg role="img" aria-labelledby="title">
<span id="title">Pass</span>
</svg>
<svg role="img" aria-label="title">
<span id="title">Pass</span>
</svg>
<svg role="graphics-symbol">
<title>Pass</title>
<rect />
</svg>
<svg aria-hidden="true"><rect /></svg>
<svg role="img" aria-label="">
<span id="">Pass</span>
</svg>
<svg role="presentation">foo</svg>
Document 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
## Description
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 to `svg`
- provide `role="img"` and `aria-label` or `aria-labelledby` to `svg`
## Examples
### Invalid
```html
<svg>foo</svg>
<svg>
<title></title>
<circle />
</svg>
<svg role="img" title="title">
<span id="">foo</span>
</svg>
<svg role="img" aria-labelledby="title">
<span id="title2">foo</span>
</svg>
<svg>
<rect />
<rect />
<g>
<title>foo</title>
<circle />
<circle />
</g>
</svg>
<svg role="graphics-symbol"><rect /></svg>
<svg>
<title>Pass</title>
<circle />
</svg>
<svg role="img" aria-labelledby="title">
<span id="title">Pass</span>
</svg>
<svg role="img" aria-label="title">
<span id="title">Pass</span>
</svg>
<svg role="img" aria-label="">
<span id="">Pass</span>
</svg>
<svg role="graphics-symbol">
<title>Pass</title>
<rect />
</svg>
<svg aria-hidden="true"><rect /></svg>
<svg role="presentation">foo</svg>
Document 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