Overview
The accessibility panel is a Panel that a FAB opens on every page. It has three groups. Accessibility Modes are switches that turn on several settings at once. Readable Experience holds tiles for text size, spacing, alignment, highlights, motion and the reading mask. Visually Pleasing Experience holds the color filters. Each choice writes a token on <html>, and CSS changes the page from that token.
Pick another component when:
Markup
The FAB ships hidden, and the FAB script shows it once it is docked. A new page needs its own copy, after the footer.
Behavior
Triggers
Any button with data-accessibility-toggle and data-panel-toggle opens the panel, as the FAB does. The first attribute builds the panel on the first press, with a spinner on the button for about one second. The second opens and closes the panel after that. To open it from your own code, call NDS.Accessibility.open(), as in the API.
While settings are on, each trigger shows how many on a badge over its icon, as the Filter button does. The number is the sum of the three group counts, and it is also added to the button’s name for screen readers, such as “Accessibility settings (3)”. A trigger with no icon shows no badge.
Panel Position
The panel slides in from the end edge, and the FAB docks there too. To move both, set data-panel-side on the FAB: with data-fab-side="auto", the FAB docks on that side too. The first button pressed builds the panel on its own data-panel-side, so give every trigger the same value. A custom panel uses the data-panel-side on its <aside>.
Loading
The script loads at page load only for a visitor with saved settings, so their modes apply without a press. Its CSS loads with it, so the page can show without the saved modes for a moment. To stop that flash, add <link rel="stylesheet" href="assets/css/nds-accessibility.min.css"> in <head>, after the main stylesheet. A preload does not stop it. The link blocks the first paint for every visitor.
Custom Panel
To change the panel, put your own copy in a <template class="nds-panel-template"> on every page that has the FAB. It replaces the panel the script builds. The copy below is that panel, with its English text. NDS still writes the page language’s word into every element that keeps a data-i18n or data-i18n-{attribute} marker. Remove the marker to keep your own text.
Removal
To remove the panel from a page, delete its FAB and every other data-accessibility-toggle button. With none on the page, nothing of the panel loads, even for a visitor with saved settings.
Text
The panel reads its English from the script and its Arabic from the accessibility section of assets/i18n/ar.json. To change some of it, set window.NDS_I18N.accessibility before the NDS scripts: each key you set replaces that text, and the rest keep the file’s text. See Internationalization.
Built-in Features
-
Auto-initialization
The page carries only the FAB. The script and the panel load on the first press, so a visitor who never opens the panel downloads none of it.
-
Seven Accessibility Modes
One switch each for epilepsy, visual impairment, cognitive load, motor impairment, color blindness, dyslexia and ADHD. A mode changes only the settings the visitor left at default. Turning it off restores each one the visitor did not change since.
-
Ten Readable Tiles
Font size, dyslexia font, title and link highlights, reading mask, motion pause, text alignment, line height, letter spacing and word spacing. A tile with levels shows a bar for each one.
-
One Color Filter at a Time
Boost contrast, monochrome, high contrast, high saturation, low saturation and a deuteranopia simulation. Turning one on turns the others off. Except High Contrast, the filters do not apply while a Windows contrast theme is on.
-
Reading Mask
Dims the screen except for one band. The band stays put on scroll and moves only by drag or by key. Its toolbar changes the band's height or closes the mask, and moves above the band when there is no room below. The band keeps its place after a reload.
-
Cross-Page Persistence
Every choice is saved in
localStorage['nds-a11y']and applies on every page. When every setting is back at default, the key is removed. -
OS Preference Sync
The device's reduced motion and more contrast settings turn on Pause Motion and High Contrast. A change to them during the visit applies at once.
-
Localized Live Announcements
A screen reader hears every change and reset in the page's language. The text comes from the
accessibilitysection of the pack. -
Two-Press Reset
The first press on Reset Settings starts a 5-second countdown on the button. A second press within it resets everything.
Best Practices
- Keep the FAB on every page. A visitor who set the panel up on one page expects to find it on the next.
- Add a second trigger in the footer or the main menu. A keyboard user then reaches the panel in the normal tab order.
- Put a trigger where the visitor reads. Focus goes back to it when the panel closes, and the browser scrolls to it.
- Move the FAB and the panel to the start edge when a chat widget or a sticky button holds the end corner.
- Do not build your own switches for these modes. They would conflict with the saved settings. Link to the panel, or call
NDS.Accessibility.toggleMode(). - Write your own
--typo-*tokens ascalc(value * var(--user-font-scale, 1)), so Font Sizing scales them too. - Check your own colors with High Contrast on, in light and dark mode. High Contrast swaps the semantic color tokens, so a color that does not use them stays the same.
- Do not offer the Deuteranopia filter as an aid. It shows what a visitor with deuteranopia sees, for design checks. Visitors get real correction from their device’s color filters.
API
Classes
| Class | Element | Effect |
|---|---|---|
nds-accessibility-toggle |
the FAB | Names the FAB for your own CSS. NDS gives it no styles, and nds-fab docks it |
nds-accessibility-panel |
the panel <dialog> |
Fixes the panel’s text sizes, so Font Sizing and the dyslexia font do not change the panel. Pair it with nds-panel |
nds-panel-template |
a <template> |
Holds your own panel. See Panels |
nds-accessibility-modes |
the accordion in the panel | Sets the padding of the mode switches |
nds-accessibility-quick |
a row in the panel body | The row of quick buttons, such as the theme button |
nds-accessibility-tile-bars |
a span in a tile with levels | Holds the level bars. The script adds one nds-accessibility-tile-bar for each level |
nds-a11y-count |
a tag in an accordion title | Shows the number of controls that are on in that group. It hides while empty |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-accessibility-toggle |
the FAB, or any button outside the panel | The first press loads the script and builds the panel. Pair it with data-panel-toggle |
data-panel-toggle |
the same button | ="nds-accessibility-panel". Opens and closes the built panel and sets aria-expanded. The script adds aria-controls once it builds the panel, so the markup leaves it out. See Panels |
data-panel-side |
every data-accessibility-toggle button |
The edge the panel slides from: end (default), start, left or right. start and end flip with the text direction. The script copies it from the first button pressed onto the panel it builds |
data-fab-side |
the FAB | The FAB’s edge: start, end, left, right or bottom. auto docks on the FAB’s data-panel-side. See FAB |
data-state~="loading" |
the pressed button | The script sets it while the panel loads, and removes it about one second later |
data-accessibility-panel |
the panel <dialog> |
Marks the panel. A panel already in the page is used instead of a template |
data-armed |
the panel <dialog> |
The script sets it when it builds the panel |
data-a11y-status |
a screen-reader role="status" element in the panel |
The script writes each announcement in it |
data-a11y-count |
the count tag in an accordion title | modes, readable or visual. The script writes the group’s count in it. It counts inside #a11y-modes-collapse, #a11y-readable-collapse and #a11y-visual-collapse, so keep those ids |
data-a11y-count-sr |
a screen-reader span next to the tag | The same group names. The script writes the count as text for screen readers |
data-a11y-mode |
a mode switch input, or a tile button | The mode or token the control turns on and off: a name from Modes or from Tokens on <html> |
data-a11y-setting |
a tile button with levels | The setting the tile changes. The panel’s values: font-step 0,1,2,3, text-align default,end,start,justify, line-height normal,1.6,1.8,2.0, letter-spacing 0,0.04em,0.08em,0.12em, word-spacing 0,0.16em,0.32em,0.48em |
data-a11y-cycle |
the same tile button | The values a press steps through, separated by commas. The first value is the default |
data-a11y-bars |
a span in that tile | The script adds one bar for each value after the first |
data-a11y-value |
a screen-reader span in that tile | The script writes the current value in it |
data-a11y-visual |
a filter tile button | The filter the tile turns on. Turning it on turns the other filters off |
data-a11y-exclude-token |
a tile button | letter-spacing: the script removes the tile on a page whose language is written in a script that joins its letters, such as Arabic, Persian or Urdu, because letter spacing breaks them. The browser names the script from lang on <html>. A saved letter spacing does not apply there either |
data-state~="selected" |
a tile button | The script sets it, with aria-pressed="true", while the tile is on, and removes it when the tile turns off |
data-accessibility-action |
the reset button | ="reset". Two presses within 5 seconds reset every setting |
data-state~="arming" |
the reset button | The script sets it after the first press, and removes it after the second press or after 5 seconds |
data-a11y |
<html> |
The script writes the tokens that are on, separated by spaces. See Tokens on <html> |
CSS Custom Properties
| Property | Default | Controls |
|---|---|---|
--user-font-scale |
1 |
The scale of every --typo-* token. Set it on <html>: the tokens resolve there, so on another element it changes nothing. The font-step-* tokens set it |
--user-line-height |
normal |
The line height of body text. The script writes it on <html> |
--user-letter-spacing |
0 |
The letter spacing of body text. The script writes it on <html> |
--user-word-spacing |
0 |
The word spacing of body text. The script writes it on <html> |
The panel’s width and top come from Panels. The FAB’s distance from the edge comes from FAB.
Modes
Pass the mode name to toggleMode().
| Mode | Turns on | WCAG |
|---|---|---|
epilepsy-safe |
reduce-motion, low-saturation |
2.3.1 |
visually-impaired |
high-contrast, font-step-2 |
1.4.6 |
cognitive-disability |
highlight-titles, reduce-motion |
2.2, 2.3 |
motor-impaired |
motor-impaired |
2.5.5 |
colorblind |
cvd-deutan |
1.4.1 |
dyslexia-friendly |
dyslexia, highlight-links, line height 1.6, letter spacing 0.12em, word spacing 0.16em |
1.4.8, 1.4.12 |
adhd-friendly |
reduce-motion, highlight-titles, reading-mask |
2.2, 2.3 |
Tokens on <html>
CSS reads these tokens with [data-a11y~="…"]. A mode writes the tokens of the settings it turns on, not its own name. Only Motor Impaired writes its own name.
| Token | Set by | Effect |
|---|---|---|
reduce-motion |
Pause Motion. The Epilepsy Safe, Cognitive Disability and ADHD Friendly modes. The device’s reduced motion setting | Stops animations and transitions, and pauses autoplay video and audio once. Progress bars, progress rings and loading spinners keep moving |
high-contrast |
High Contrast. The Visually Impaired mode. The device’s more contrast setting | Swaps the semantic color tokens for black on white, or white on black in dark mode |
boost-contrast |
Boost Contrast | filter: contrast(1.15) on the page |
monochrome |
Monochrome | filter: grayscale(1) on the page |
high-saturation |
High Saturation | filter: saturate(2) on the page |
low-saturation |
Low Saturation. The Epilepsy Safe mode | filter: saturate(0.5) on the page |
cvd-deutan |
Deuteranopia. The Colorblind mode | Shows the page as a visitor with deuteranopia sees it. It uses the color matrix of Chrome DevTools’ vision deficiency emulation |
dyslexia |
Dyslexia Friendly. The Dyslexia Friendly mode | Changes the font to OpenDyslexic for Latin text and Maqroo for Arabic text, and sets body text to weight 500 |
highlight-titles |
Highlight Titles. The Cognitive Disability and ADHD Friendly modes | Outlines every heading in the warning colors |
highlight-links |
Highlight Links. The Dyslexia Friendly mode | Gives every link a dashed outline, and underlines text links |
reading-mask |
Reading Mask. The ADHD Friendly mode | Shows the reading mask at z-index: 850. A layer below that is dimmed with the page |
motor-impaired |
The Motor Impaired mode | Makes every button at least 48 × 48px |
font-step-1, font-step-2, font-step-3 |
Font Sizing. The Visually Impaired mode sets step 2 | Sets --user-font-scale to 1.15, 1.30 or 1.50 |
text-align-start, text-align-end, text-align-justify |
Text Alignment | Aligns paragraphs and list items |
has-line-height, has-letter-spacing, has-word-spacing |
Line Height, Letter Spacing and Word Spacing. The Dyslexia Friendly mode sets 1.6, 0.12em and 0.16em, with no letter spacing on a page whose script joins its letters, such as Arabic | Applies the matching --user-* value to paragraphs, lists and quotes |
The text and highlight rules reach only the page’s header, main and footer, so the panel and the FAB keep their look.
Reading Mask Keyboard
| Key | Effect |
|---|---|
Arrow Up, Arrow Down |
Moves the band 20px. Focus must be on the move button in the mask toolbar |
Page Up, Page Down |
Moves the band 100px |
Home, End |
Moves the band to the top or the bottom of the screen |
Escape |
Turns the reading mask off, when the panel is closed |
The toolbar’s size buttons change the band’s height in 40px steps, from 40px to 320px.
JavaScript
| Method | Effect |
|---|---|
NDS.Accessibility.open(trigger) |
Opens the panel. The first call builds it and shows the spinner on trigger |
NDS.Accessibility.close() |
Closes the panel |
NDS.Accessibility.toggle(trigger) |
Opens or closes the panel |
NDS.Accessibility.toggleMode(name) |
Turns a mode or a token on or off |
NDS.Accessibility.setVisualFilter(name) |
Turns on one filter and turns off the others. The same name again turns it off |
NDS.Accessibility.cycleSetting(key, values) |
Sets key to the value after its current one in values |
NDS.Accessibility.reset() |
Resets every setting at once, with no second press |
NDS.Accessibility.state |
A copy of the saved settings. Changing it changes nothing |
NDS.Accessibility.isReady |
true once the panel is built and wired |
NDS.Accessibility.isStarted |
true once init() has run, from a press or from the loader |
NDS.Accessibility.init(trigger) |
Builds and wires the panel. The first press calls it, so you rarely need it |
Before the script loads, NDS.Accessibility is a stub. A call to it loads the script, then runs. The component fires no events. Open the panel from a menu link:
The full API is in the banner of _js/nds-accessibility.js.