--- 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. Some warnings may be incorrect in your concrete use case. You can disable such false positives by placing a `` comment above the line that causes the warning. Example: ```svelte ``` 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. ```svelte
``` ## `a11y-aria-activedescendant-has-tabindex` An element with `aria-activedescendant` must be tabbable, so it must either have an inherent `tabindex` or declare `tabindex` as an attribute. ```svelte
``` ## `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. ```svelte ``` ## `a11y-autofocus` Enforce that `autofocus` is not used on elements. Autofocusing elements can cause usability issues for sighted and non-sighted users alike. ```svelte ``` ## `a11y-click-events-have-key-events` Enforce `on:click` is accompanied by at least one of the following: `on:keyup`, `on:keydown`, `on:keypress`. Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screenreader users. This does not apply for interactive or hidden elements. ```svelte
{}} /> ``` Note that the `keypress` event is now deprecated, so it is officially recommended to use either the `keyup` or `keydown` event instead, accordingly. ## `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 ``. ```svelte ``` ## `a11y-hidden` Certain DOM elements are useful for screen reader navigation and should not be hidden. ```svelte ``` ## `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_. ```svelte Foo eating a sandwich. Photo of foo being weird. Image of me at a bar! Picture of baz fixing a bug. ``` ## `a11y-incorrect-aria-attribute-type` Enforce that only the correct type of value is used for aria attributes. For example, `aria-hidden` should only receive a boolean. ```svelte
``` ## `a11y-invalid-attribute` Enforce that attributes important for accessibility have a valid value. For example, `href` should not be empty, `'#'`, or `javascript:`. ```svelte invalid ``` ## `a11y-interactive-supports-focus` Enforce that elements with an interactive role and interactive handlers (mouse or key press) must be focusable or tabbable. ```svelte
{}} /> ``` ## `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. ```svelte ``` ## `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. ```svelte