Accessibility requirements relevant to front-end development cluster around issues of screen reader hinting, keyboard and mobile compatibility, and interactive and form controls.
- Key Concepts
- Developers Guide
- A Quick Self-Led Training
- Further Reading and Online Classes
- Imitation is the sincerest form of flattery. Creating accessible forms and interactive elements is hard. Whenever possible, use accessible frameworks and design patterns.
- Test as you work. Running quick automated and keyboard tests will naturally guide you into discovering and fixing many of the items on this page.
- Know how screen readers read. Screen reader users skim headings, regions or links to indicate items of interest, and they expect to hear their readers always announce the name, role and value of components: "Visited [value] link [role]: headings, regions or links [name]."
- Beware the :hover state:
- Keyboard users use the Tab key (or the equivalent) to advance through links and interactive elements. They need :focus states on elements to see where their cursor is, keyboard click event handlers for custom buttons, and skip links to get past navigation.
- Screen readers often do not trigger hover OR focus events. Screen readers in their default mode explore pages using a virtual cursor, and do not advance the "real" cursor unless the user clicks to interact. This is incompatible with some menu design patterns.
- Automatically playing media can present significant obstacles to many users; screen readers cannot be heard over audio, and users with vestibular (motion sickness), reading, or attention disorders may have trouble interacting with text near animated elements.
- Help screen reader users skim:
- Use clear and specific page titles.
- Structure the page with HTML landmark regions (header, nav, main, footer).
- Use headers to label key regions, such as the navigation, search and footer, as well as any alerts. These labels can be visually hidden.
- Differentiate reusable landmarks like <nav> elements with headings or aria-labels: (the main "site" navigation, the vertical "section" navigation).
- Make sure every focusable element contains accessible text or an aria label, especially icon buttons.
- Use semantic elements (regions, lists, figures, tables, etc). They are understood and announced by screen readers, and many have special browsing modes (jump to next region/cell/list item/row); simple containers (<div>, <span>) do not provide any of this.
- Don't visually reorder elements and regions. Keyboards and assistive devices read the DOM order, and users expect that to match the visual reading order (left to right, top to bottom).
- Provide a "skip to main" link, and point it at a named anchor set to tabindex="-1". Targeting unfocusable elements may scroll them into view, but only focusable targets actually transfer focus for keyboard users!
- Validate your HTML.
- Never disable viewport zoom.
- Refrain from limiting the height of text containers. Up to 3% of users have modified their default font or font size, which can cause unexpected overflows of fixed-size containers. At a minimum, try to size elements relative to the font size (em or rem) instead of using px units.
- Make sure your code supports accessible design considerations for device flexibility regarding element scaling for small, large, low PPI and high PPI devices.
- Expect users to commonly have viewports as narrow as 320px and as wide as 2560px.
- Make sure your code works in both portrait and landscape.
- Do not assume users viewing your narrowest (mobile) breakpoint will not be using a keyboard and/or mouse. Their phone may be paired with an input device, or they may be on a desktop with a screen magnifier. Your mobile theme still needs :focus indicators and keyboard click handlers.
- Do not assume users viewing your widest (desktop) breakpoint will not be using a touchscreen. Large tablets have viewports wider than 1280px. Your desktop theme still needs touch handlers and cannot rely on :hover.
- Make sure every form element has an accessible label for screen readers, and can be operated by a keyboard.
- Identify errors specifically, and be sure to tag errors well for screen readers. Be as helpful as possible; e.g., "Please provide your birthday as YYYY-MM-DD," rather than "Invalid date format."
- If your form has a time limit of less than a day, make sure it can be extended or disabled, unless one of the exceptions in the "Enough Time" guideline applies.
- If your form handles legal commitments or financial transactions, be sure to read the detailed guidelines regarding user review, correction and confirmation.
Consult the W3C Forms Tutorial for more depth and code samples.
Modals, Slideshows, Menu Bars, Accordions, Tab Panels...every part of an interactive component, from its outer container to its buttons, status messages and focus transfers, needs to be accessible to keyboards and screen readers. Whenever possible, use pre-tested accessible frameworks or design patterns.
Before creating your own interactive components, read the MDN WAI-ARIA basics.
Some general tips:
- Every focusable element (links, buttons, fields and anything with a tabindex value of 0 or greater) must have a clear, visible visual indication of :focus.
- Make sure element triggers work with all input devices; elements sensitive to :hover (e.g. menu flyouts) should also react to :focus...and screen readers that cannot hover or focus should have some way to get to the same content.
- Manage keyboard focus in the same way you manage visual attention grabbing:
- If that element can be closed, transfer focus back to the button that launched it after it closes.
- If you plan to implement any custom event handling, first read the guidelines regarding multipoint or path-based gestures, motion actuation and down-event pointer cancellation.
- Character key shortcuts can conflict with many assistive devices; make sure any shortcuts can disabled or remapped, or are only affect particular focused components.
- Users can pause, stop or hide any non-essential motion that starts automatically and lasts more than 5 seconds.
There are five recommended design patterns for hiding elements, depending on who you want to hide the content from:
- The CSS clip pattern hides an element visually.
- Used to visually hide items assistive devices should still be able to reach and read, such as assistive text or keyboard-only elements that will appear on :focus.
- An attribute of tabindex="-1" hides an element from the Tab key.
- Used to remove default keyboard functionality from otherwise focusable elements, such as temporarily disabled parts of forms.
- An attribute of aria-hidden="1" prevents a screen reader from reading any text in the marked element or its children.
- Used to hide inaccessible pieces of elements with accessible alternatives, such as the icon inside a button with a separate, accessible label.
- This attribute should never be given to a focusable element or an element with focusable children, as the screen reader will still be able reach the element, but will not be able to say anything when it gets there. Few things are more detrimental to a screen reader user than silence.
- Combining tabindex="-1" and aria-hidden="1" hides otherwise visible elements from screen readers and keyboard access, and removes them from screen reader element lists.
- Used mark redundant visual elements as skippable by assistive devices, e.g., links that say "read more" in news cards with independently linked headlines.
- Setting an element to CSS display:none; or HTML hidden completely hides the element visually and from assistive devices.
- Used for elements that should be completely unreachable at the moment and should not appear when focused, such as hidden panels in tabbed interfaces and accordions.
- Important note: never use display:none on structural headers and page regions, as this removes these key elements from screen reader jump-to lists. If you want to hide key regions like site navigation or search until a toggle button is pressed, a good design pattern is to put the toggle buttons inside the <nav> and <search> regions, after the only-visually-hidden structural <h2> header, and only mark the actual search field or navigation list as display:none. This pattern makes it so screen readers always have "Navigation" and "Search" regions and headers available in their jump-to lists as shortcuts to the toggle buttons:
Hiding Patterns Compared
|Method||Visual State||Keyboard State||Screen Reader State|
|tabindex||Visible||Unfocusable||Readable but unfocusable|
|aria-hidden||Visible||Focusable||Unreadable but focusable|
|tabindex and aria-hidden||Visible||Unfocusable||Hidden|
- Explore the W3C Annotated Accessible Homepage, which provides annotated right/wrong examples, including code samples.
- Read our guide to DIY testing, and do some DIY tests on the W3C demo site:
- Try to navigate the inaccessible and accessible versions with your keyboard. Note the dramatic differences in focus indication.
- Explore the W3C demonstration again in the WebAIM Wave Tool, to practice doing your own automated testing.
- Accessibility For Web Design is a short, 2-hour class covering many elements of accessible front-end development, and is available through Princeton's LinkedIn Learning portal.
- Princeton's Safari Tech Subscription provides access to several recent books on accessibility in design and front-end development, including the excellent Accessibility for Everyone.
- The MDN Accessibility Web Docs have extensive topical tutorials and documentation.
- Google provides a quick Accessible Development Guide and in-depth Web Accessibility course.
- Teach Access combines code samples for common components with tips for testing them in the VoiceOver screen reader.
- The official specifications:
- How to Meet WCAG
- The Authoring Tools Accessibility Guidelines (ATAG) expand WCAG for people developing tools to create and edit content. In short: not only do the tools need to be accessible, but they also needs to be able to generate accessible content (e.g., alt elements and table headers), and they should encourage the creation of accessible content through templates, inline helps and validators.