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.
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.
a11y-autofocus
Enforce that autofocus
is not used on elements. Autofocusing elements can cause usability issues for sighted and non-sighted users alike.
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: <marquee>
and <blink>
.
a11y-hidden
Certain DOM elements are useful for screen reader navigation and should not be hidden.
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.
a11y-invalid-attribute
Enforce that attributes important for accessibility have a valid value. For example, href
should not be empty, '#'
, or javascript:
.
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.
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.
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.
a11y-misplaced-scope
The scope attribute should only be used on <th>
elements.
a11y-missing-attribute
Enforce that attributes required for accessibility are present on an element. This includes the following checks:
<a>
should have an href (unless it's a fragment-defining tag)<area>
should have alt, aria-label, or aria-labelledby<html>
should have lang<iframe>
should have title<img>
should have alt<object>
should have title, aria-label, or aria-labelledby<input type="image">
should have alt, aria-label, or aria-labelledby
a11y-missing-content
Enforce that heading elements (h1
, h2
, etc.) and anchors have content and that the content is accessible to screen readers
a11y-mouse-events-have-key-events
Enforce that on:mouseover
and on:mouseout
are accompanied by on:focus
and on:blur
, respectively. This helps to ensure that any functionality triggered by these mouse events is also accessible to keyboard users.
a11y-no-redundant-roles
Some HTML elements have default ARIA roles. Giving these elements an ARIA role that is already set by the browser has no effect and is redundant.
a11y-positive-tabindex
Avoid positive tabindex
property values. This will move elements out of the expected tab order, creating a confusing experience for keyboard users.
a11y-structure
Enforce that certain DOM elements have the correct structure.
a11y-unknown-aria-attribute
Enforce that only known ARIA attributes are used. This is based on the WAI-ARIA States and Properties spec.
a11y-unknown-role
Elements with ARIA roles must use a valid, non-abstract ARIA role. A reference to role definitions can be found at WAI-ARIA site.