--- title: Accessibility warnings --- Accessibility (shortened to a11y) isn't always easy to get right, but Svelte will help by warning you at compile time if you write inaccessible markup. However, keep in mind that many accessibility issues can only be identified at runtime using other automated tools and by manually testing your application. Here is a list of accessibility checks Svelte will do for you. --- ### `a11y-accesskey` Enforce no `accesskey` on element. Access keys are HTML attributes that allow web developers to assign keyboard shortcuts to elements. Inconsistencies between keyboard shortcuts and keyboard commands used by screen reader and keyboard-only users create accessibility complications. To avoid complications, access keys should not be used. ```sv
``` --- ### `a11y-aria-attributes` Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `aria-*` props. ```sv ``` --- ### `a11y-autofocus` Enforce that `autofocus` is not used on elements. Autofocusing elements can cause usability issues for sighted and non-sighted users alike. ```sv ``` --- ### `a11y-distracting-elements` Enforces that no distracting elements are used. Elements that can be visually distracting can cause accessibility issues with visually impaired users. Such elements are most likely deprecated, and should be avoided. The following elements are visually distracting: `` and ``. ```sv ``` --- ### `a11y-hidden` Certain DOM elements are useful for screen reader navigation and should not be hidden. ```sv ``` --- ### `a11y-img-redundant-alt` Enforce img alt attribute does not contain the word image, picture, or photo. Screen readers already announce `img` elements as an image. There is no need to use words such as _image_, _photo_, and/or _picture_. ```sv Foo eating a sandwich. Photo of foo being weird. Image of me at a bar! Picture of baz fixing a bug. ``` --- ### `a11y-invalid-attribute` Enforce that attributes important for accessibility have a valid value. For example, `href` should not be empty, `'#'`, or `javascript:`. ```sv invalid ``` --- ### `a11y-label-has-associated-control` Enforce that a label tag has a text label and an associated control. There are two supported ways to associate a label with a control: - Wrapping a control in a label tag. - Adding `for` to a label and assigning it the ID of an input on the page. ```sv ``` --- ### `a11y-media-has-caption` Providing captions for media is essential for deaf users to follow along. Captions should be a transcription or translation of the dialogue, sound effects, relevant musical cues, and other relevant audio information. Not only is this important for accessibility, but can also be useful for all users in the case that the media is unavailable (similar to `alt` text on an image when an image is unable to load). The captions should contain all important and relevant information to understand the corresponding media. This may mean that the captions are not a 1:1 mapping of the dialogue in the media content. However, captions are not necessary for video components with the `muted` attribute. ```sv ``` --- ### `a11y-misplaced-role` Certain reserved DOM elements do not support ARIA roles, states and properties. This is often because they are not visible, for example `meta`, `html`, `script`, `style`. This rule enforces that these DOM elements do not contain the `role` props. ```sv ``` --- ### `a11y-misplaced-scope` The scope attribute should only be used on `` elements. ```sv
``` --- ### `a11y-missing-attribute` Enforce that attributes required for accessibility are present on an element. This includes the following checks: - `` should have an href (unless it's a [fragment-defining tag](https://github.com/sveltejs/svelte/issues/4697)) - `` should have alt, aria-label, or aria-labelledby - `` should have lang - `