Skip to content

API reference

Every option, theme key, method and export of the package, with its type and default.

On this page

Options

Passed to init(options), as props of AccessibilityWidget, or later to widget.setOptions(options).

Options
NameTypeDefaultDescription
position"left" | "right""left"Screen side of the launcher and panel.
offset{ x?: number; y?: number }{ x: 24, y: 24 }Distance from the screen edges, in px (0–1000).
themeAccessibilityThemeColors, radius and font: see Theme below.
colorScheme"auto" | "light" | "dark""auto"Light or dark panel. "auto" follows the page: dark while the site's own background is dark, however the site switches themes. Panel colors set in theme turn "auto" off.
iconstring | Elementbuilt-in iconLauncher logo: an image URL or a DOM element. Pass only trusted elements: they are cloned as they are.
logostring | Element | nullhiddenLogo next to the panel title.
buttonSizenumber56Launcher diameter, in px (24–160).
featuresPartial<Record<FeatureKey, boolean>>all onSet a control to false to remove it. A removed setting stays off.
initialSettingsPartial<AccessibilitySettings>Settings for visitors with nothing saved.
languagesAccessibilityLanguage[] | falseEnglish + ArabicEntries of the language menu, or false to hide the menu.
languagestringsaved → <html lang> → firstStarting language code.
labelsPartial<AccessibilityLabels>Override single strings on top of the active language.
dir"ltr" | "rtl"language's directionForce the widget's text direction.
shortcutstring | false"Alt+A"Shortcut that opens and closes the panel and brings the widget back after “Hide widget”. With false, the hide button is removed.
statementUrlstringLink to your accessibility statement in the panel's footer (http, https or relative).
feedbackUrlstringWhere visitors report an accessibility problem (a page, a form or mailto:), shown in the panel's footer.
showSkipLinkbooleantrueA “Skip to main content” link. Left out when the page has no main or h1, or already starts with its own skip link.
zIndexnumber2147483000Stacking order of the widget.
persistbooleantrueSave settings in localStorage, kept in sync across tabs.
storageKeystring"a11yw-settings"localStorage key.
noncestringCSP nonce for the injected style tags.
onChange(settings) => voidCalled when the visitor changes something.

Theme

The keys of the theme option. Colors take any CSS color; only hex colors are checked for contrast.

Theme
NameTypeDescription
primarystringBrand color: launcher, header and active states.
onPrimarystringText and icon color on top of primary.
backgroundstringPanel background.
surfacestringFooter, segmented controls and hover states.
text, mutedTextstringText and secondary text.
borderstringBorders.
radiusnumber | stringCorner radius: a number in px or any CSS length.
fontFamilystringFont stack of the panel.

Instance methods

init() returns the widget. The script-tag build exposes the same exports on window.A11yWidget.

TypeScript
import { init } from "open-accessibility-widget";

const widget = init();

widget.open(); widget.close(); widget.toggle();
widget.getSettings();                                  // a frozen snapshot
widget.setSettings({ fontSize: 120 });                 // validated: bad values are dropped
widget.setSettings((s) => ({ fontSize: s.fontSize + 10 }));
widget.toggleProfile("visionImpaired");
widget.reset();
widget.setOptions({ theme: { primary: "#000000" }, language: "ar" });
const unsubscribe = widget.subscribe(({ settings, isOpen }) => {});
widget.destroy();                                      // removes the widget and undoes every change
Instance methods
NameTypeDescription
open(), close(), toggle()voidOpen, close or toggle the panel.
getSettings()AccessibilitySettingsThe current settings, as a frozen snapshot.
getState()AccessibilityStateThe settings and whether the panel is open.
setSettings(update)voidMerge changes: an object, or a function of the previous settings. Input is validated and invalid values are dropped. Setting profiles applies their adjustments too.
toggleProfile(id)voidTurn a profile on or off.
reset()voidReturn every adjustment to the page as authored.
setOptions(options)voidChange appearance and behaviour options at runtime.
subscribe(listener)() => voidListen to settings and open-state changes. Returns a function that stops listening.
destroy()voidRemove the widget and undo every change it made to the page.

React

From open-accessibility-widget/react, which also re-exports everything else. The entry is marked "use client".

React
NameTypeDescription
<AccessibilityWidget {...options} />nullMounts the widget with these options. Changed props call setOptions(); unmounting removes the widget. Renders nothing itself.
useAccessibility(){ settings, isOpen, widget }Read and control the widget from any component. widget is null until it mounts.

Exports

Named exports of the package.

Exports
NameTypeDescription
init(options), createAccessibilityWidget(options)AccessibilityWidgetInstanceMount the widget on body and return it. Calling it again replaces the existing widget.
getAccessibilityWidget()AccessibilityWidgetInstance | nullThe widget that is running, if any.
onActiveWidgetChange(listener)() => voidListen for a widget being created or destroyed. Returns a function that stops listening.
DEFAULT_SETTINGSReadonly<AccessibilitySettings>Every setting at its default.
RANGESRecord<RangeKey, { min, max, step }>Minimum, maximum and step of each percentage setting.
PROFILE_IDS, PROFILE_PRESETSProfileId[], Record<ProfileId, ProfilePreset>The profile ids, and the adjustments each profile switches on.
sanitizeSettings(input)AccessibilitySettingsValidate untrusted input into complete settings.
builtInLanguagesAccessibilityLanguage[]English and Arabic, to extend with your own languages.
defaultLabels, arabicLabelsAccessibilityLabelsThe English and Arabic strings.

Settings

What getSettings() returns, and what setSettings() and initialSettings accept. Percentages use 100 for unchanged; values outside the range are clamped and unknown values dropped.

Settings
NameTypeDefaultDescription
profilesProfileId[][]Active profiles, in the order they were turned on.
contentScalenumber (50–200)100Page zoom, in percent.
fontSizenumber (50–200)100Text size, in percent.
lineHeightnumber (100–200)100Line spacing, in percent.
letterSpacingnumber (100–200)100Letter spacing, in percent (not applied to Arabic).
textAlign"default" | "left" | "center" | "right" | "justify""default"Text alignment.
readableFontbooleanfalseA plain, readable font.
boldTextbooleanfalseAll page text in bold.
highlightTitles, highlightLinksbooleanfalseOutline headings / links.
textMagnifierbooleanfalseShows the text under the pointer or focus, enlarged (an image's alt text for images).
readAloudbooleanfalseA click, tap or keyboard focus reads that block aloud with the browser's own speech, in the page's language. Escape stops it.
colorMode"default" | "dark-contrast" | "light-contrast" | "high-contrast""default"Contrast mode.
saturationMode"default" | "monochrome" | "low-saturation" | "high-saturation""default"Saturation filter.
invertColorsbooleanfalseInverts the page's colors; images and video keep theirs.
textColor, titleColor, backgroundColor"#rrggbb" | nullnullCustom text, heading and background colors.
muteSounds, hideImages, stopAnimationsbooleanfalseMute media, hide images, stop CSS animations.
readingGuide, readingMaskbooleanfalseReading line and focus window.
highlightFocus, highlightHoverbooleanfalseStrong outline on keyboard focus / on hover.
cursor"default" | "black" | "white""default"Large cursor.

Package contents

Each entry ships ESM, CommonJS and type declarations. No runtime dependencies.

Package contents
NameTypeDescription
open-accessibility-widgetESM + CJS + .d.tsAny framework, or plain JavaScript with a bundler.
open-accessibility-widget/reactESM + CJS + .d.tsReact component and hook; react 18 or later is an optional peer dependency.
open-accessibility-widget/languagesESM + CJS + .d.tsOptional extra languages (14), tree-shakable, about 1 KB gzipped each.
dist/open-accessibility-widget.global.jsIIFEScript-tag build, about 27 KB gzipped; exposes window.A11yWidget.
dist/open-accessibility-widget.languages.global.jsIIFEScript-tag language pack, about 17 KB gzipped; exposes window.A11yWidgetLanguages.

Edit this page on GitHub