Skip to main content
Svelte has built-in accessibility (a11y) features that help you create inclusive applications. The compiler analyzes your markup and provides warnings for common accessibility issues at build time.

Compiler Warnings

Svelte’s compiler catches potential accessibility mistakes during development, helping you fix issues before they reach production.

Disabling Warnings

If a warning is a false positive for your use case, disable it with a comment:
You can list multiple rules and add explanatory notes:

Common Accessibility Warnings

Interactive Elements

Click Events Need Keyboard Support

Warning: a11y_click_events_have_key_events Visible, non-interactive elements with click handlers must also support keyboard interaction:
Prefer semantic HTML elements like <button> and <a> over <div> with event handlers. They have built-in keyboard support and better screen reader compatibility.

Mouse Events Need Focus Events

Warning: a11y_mouse_events_have_key_events onmouseover and onmouseout must be accompanied by onfocus and onblur:

ARIA Attributes

Required ARIA Properties

Warning: a11y_role_has_required_aria_props Elements with ARIA roles must have all required attributes:

Supported ARIA Properties

Warning: a11y_role_supports_aria_props Only use ARIA attributes supported by an element’s role:

Correct ARIA Attribute Types

Warning: a11y_incorrect_aria_attribute_type ARIA attributes must have the correct value type:

Form Elements

Labels for Form Controls

Warning: a11y_label_has_associated_control Label tags must be associated with a control:

Images and Media

Alternative Text for Images

Warning: a11y_missing_attribute Images must have alt text:
Use empty alt="" for purely decorative images so screen readers skip them.

Avoid Redundant Alt Text

Warning: a11y_img_redundant_alt Don’t include words like “image”, “photo”, or “picture” in alt text:

Captions for Video

Warning: a11y_media_has_caption Video elements must include captions:

Semantic HTML

Avoid Distracting Elements

Warning: a11y_distracting_elements Avoid deprecated elements that cause accessibility issues:

Don’t Hide Important Elements

Warning: a11y_hidden Headings and landmarks shouldn’t be hidden from screen readers:

Proper HTML Structure

Warning: a11y_figcaption_parent, a11y_figcaption_index <figcaption> must be the first or last child of <figure>:

Focus Management

Avoid Autofocus

Warning: a11y_autofocus Autofocusing can disorient users:
Only use autofocus when it’s the primary expected action and won’t surprise users.

Positive Tabindex

Warning: a11y_positive_tabindex Avoid positive tabindex values:

Interactive Roles Must Be Focusable

Warning: a11y_interactive_supports_focus Elements with interactive roles need tabindex:

ARIA Integration

Svelte uses the aria-query package to validate ARIA usage, ensuring compliance with the WAI-ARIA specification.

Valid ARIA Roles

Warning: a11y_unknown_role Only use valid ARIA roles:

No Abstract Roles

Warning: a11y_no_abstract_role Don’t use abstract ARIA roles:

Best Practices

1
  • Use semantic HTML - Prefer <button>, <nav>, <main> over generic <div> elements
  • Test with screen readers - Use NVDA, JAWS, or VoiceOver to verify your application
  • Support keyboard navigation - Ensure all functionality is accessible via keyboard
  • Provide text alternatives - Include alt text, captions, and transcripts
  • Use sufficient color contrast - Ensure text is readable for users with visual impairments
  • Respect user preferences - Honor prefers-reduced-motion and other media queries
  • Testing Accessibility

    Browser DevTools

    Modern browsers include accessibility inspectors:
    • Chrome/Edge: Accessibility pane in DevTools
    • Firefox: Accessibility Inspector
    • Safari: Accessibility Inspector in Web Inspector

    Automated Testing

    Use tools like axe-core or pa11y to catch issues:
    Svelte’s compile-time warnings catch many issues that runtime tools might miss. Pay attention to compiler warnings!

    Additional Resources