# Accessibility — a11y widget (WCAG)
Accessibility widget: a floating button that opens a panel with options for people
with disabilities (text size, contrast, grayscale, underlined links, readable font,
no animations, big cursor).
> **OPTIONAL — do not add by default.** The a11y widget is legally required
> ONLY for some sites (public bodies, some e-commerce/services covered by the
> European Accessibility Act). For most commercial sites it is an OPTION, not a
> duty. Add it WHEN the client/project requires it — not on every site
> automatically. If in doubt: ask whether the site falls under accessibility rules.
Same pattern as CookieBanner: provider + widget, wired once. Preferences live in a
cookie (no flash) and are applied as `data-a11y-*` attributes on ``.
> **Plugin/project boundary:** the plugin provides the MECHANISM (widget, state,
> cookie, attributes on html). The project provides the CSS that reacts to the
> attributes — because styles depend on the project design (colors, fonts,
> Tailwind). The plugin does NOT impose styles, so nothing clashes. Ready-to-copy
> CSS is below.
---
## 1. Wiring — Provider + Widget
```tsx
// app/(frontend)/[locale]/layout.tsx
import { AccessibilityProvider, AccessibilityWidget } from '@intecion/ipal-kit/client'
{children}
```
The widget is unstyled (like CookieBanner) — match the classNames to your design.
## Labels — English by default, configured per locale
Default labels are **English** (the plugin is multilingual, neutral at its base).
Keep translations in the project and pass the set for the active language through
`texts` (`A11yTexts`). The plugin stays content-agnostic:
```tsx
import type { A11yTexts } from '@intecion/ipal-kit/client'
const A11Y: Record = {
pl: { title: 'Dostępność', textSize: 'Rozmiar tekstu', reset: 'Resetuj', /* … */ },
de: { title: 'Barrierefreiheit', textSize: 'Textgröße', /* … */ },
}
```
Pass only the keys you want to override — the rest falls back to the English
default. You can also keep the labels in a localized global and read them from the
panel (consistent with "managed from the panel"), but that is a project decision —
the plugin only needs `A11yTexts` for the current locale.
---
## 2. CSS that reacts to the attributes (MANDATORY — project)
The widget sets attributes on ``. Without CSS for them nothing happens.
**Ready file (1.15.0):** `@import "@intecion/ipal-kit/a11y.css";` in `styles.css` — the rules below, working through
the design tokens ([design-tokens.md](./design-tokens.md)): the readable font swaps `--ipal-font-body/-heading` (set
`--ipal-font-readable` to change it), "no animations" zeroes the `--ipal-duration-*` tokens, contrast + grayscale
combine, the big cursor is built in. Check: tick each option in the widget and see the page change.
Or copy this into the project's global CSS (adapt it to the design):
```css
/* Text size */
html[data-a11y-text="1"] { font-size: 112.5%; }
html[data-a11y-text="2"] { font-size: 125%; }
html[data-a11y-text="3"] { font-size: 150%; }
/* Line spacing */
html[data-a11y-line="1"] * { line-height: 1.8 !important; }
html[data-a11y-line="2"] * { line-height: 2.2 !important; }
/* High contrast */
html[data-a11y-contrast="high"] {
filter: contrast(1.4);
}
/* Inverted contrast */
html[data-a11y-contrast="inverted"] {
filter: invert(1) hue-rotate(180deg);
}
html[data-a11y-contrast="inverted"] img,
html[data-a11y-contrast="inverted"] video {
filter: invert(1) hue-rotate(180deg); /* restore media */
}
/* Grayscale */
html[data-a11y-grayscale="on"] { filter: grayscale(1); }
/* Note: filter on html does not stack — if you combine contrast+grayscale,
apply it on body or merge it into one rule. */
/* Underlined links */
html[data-a11y-underline="on"] a { text-decoration: underline !important; }
/* Readable font (swap in your own dyslexia-friendly / simple font) */
html[data-a11y-font="readable"] * {
font-family: Verdana, Tahoma, sans-serif !important;
letter-spacing: 0.02em;
}
/* No animations */
html[data-a11y-motion="reduce"] *,
html[data-a11y-motion="reduce"] *::before,
html[data-a11y-motion="reduce"] *::after {
animation-duration: 0.001ms !important;
transition-duration: 0.001ms !important;
scroll-behavior: auto !important;
}
/* Big cursor */
html[data-a11y-cursor="big"] * {
cursor: url('/cursors/big.svg') 4 4, auto !important;
}
```
Adapt the values to the project (contrast colors, font, cursor). This is your CSS —
the plugin only sets the attributes.
> **Contrast + filter:** several options use `filter` on ``. CSS `filter` on
> one element does NOT stack values from different rules — the last one wins.
> If you want to combine them (e.g. grayscale + contrast), apply the filters on
> `body` with the full value, or build combined rules. Single options work
> without issues.
---
## 3. No flash (SSR) — optional
By default the widget applies the attributes after hydration (a short flash on load
if the user had settings). To avoid it, read the cookie server-side and set the
attributes on `` during SSR:
```tsx
// layout.tsx (server) — read the cookie and set the attributes right away
import { cookies } from 'next/headers'
import { A11Y_COOKIE, parseA11y, a11yAttributes } from '@intecion/ipal-kit'
const raw = (await cookies()).get(A11Y_COOKIE)?.value
const attrs = a11yAttributes(parseA11y(raw))
const htmlAttrs = Object.fromEntries(
Object.entries(attrs).filter(([, v]) => v !== null),
)
return ...
```
The provider re-applies and syncs on the client anyway. This only removes the flash.
### State and attributes (`A11yState`)
Cookie `a11y-prefs` (`A11Y_COOKIE`, JSON, `path=/`, `max-age` 1 year, `samesite=lax`).
It is written only when the visitor changes a setting, with no consent check: a preference the visitor
chose, no tracking (the same reasoning as the theme choice, theme.md). List it as **necessary** in the
cookie list — the scanner does not declare it, add it with `declarations` (cookie-scanner.md).
Widget texts: `texts` prop wins, otherwise `A11Y_DEFAULT_TEXTS[locale]` (`en`, `pl`; prop `locale`,
incl. `texts.on` / `texts.off` for the switches).
The helpers `A11Y_COOKIE`, `A11Y_DEFAULT`, `parseA11y`, `serializeA11y`, `a11yAttributes`
are in `@intecion/ipal-kit` (not in `/client`). The `A11yState` type is in both entries.
| State key | Values | Attribute on `` (none = default) |
|---|---|---|
| `textSize` | `0`–`3` | `data-a11y-text="1..3"` |
| `lineHeight` | `0`–`2` | `data-a11y-line="1..2"` |
| `contrast` | `'default' \| 'high' \| 'inverted'` | `data-a11y-contrast="high\|inverted"` |
| `grayscale` | boolean | `data-a11y-grayscale="on"` |
| `underlineLinks` | boolean | `data-a11y-underline="on"` |
| `readableFont` | boolean | `data-a11y-font="readable"` |
| `reduceMotion` | boolean | `data-a11y-motion="reduce"` |
| `bigCursor` | boolean | `data-a11y-cursor="big"` |
---
## 4. Separate open button (optional)
The widget has a built-in floating button. If you want to open the panel from
somewhere else (e.g. an "Accessibility" link in the footer), use the hook:
```tsx
'use client'
import { useAccessibility } from '@intecion/ipal-kit/client'
// keep the open state yourself, or extend the widget — the hook gives state/set/reset
```
---
## 5. Compliance — when accessibility is required
Accessibility (WCAG) is legally required ONLY for some sites:
- **Public bodies** (government offices, schools, institutions) — the Polish digital accessibility act
- **Large e-commerce / services** covered by the European Accessibility Act (2019/882, from 2025)
- Sites where the client requires it (company policy, public tender)
For **most commercial sites** (business card site, small company, catalog) the a11y
widget is **an option, not a duty** — add it when the client requires it, not
automatically.
When you add it: the widget by itself does NOT make the site fully accessible — it
helps the user. Full accessibility also means semantic HTML, alt texts, keyboard
navigation, baseline contrast. The widget complements, it does not replace. Do not
sell the client "we have a widget = we are WCAG compliant". See [dev/PROGRAMISTA.md](dev/PROGRAMISTA.md) §5.
## Turn off, override, extend
- **Turn off:** the module is opt-in — without `AccessibilityProvider` / `AccessibilityWidget` nothing happens
(no option in `ipalKit`, no fields in the panel).
- **Override:** the widget's `classNames` and `texts`; the whole look of the effects is project CSS.
- **Extend:** your own UI on `useAccessibility()` (`state`, `set`, `reset`); SSR helpers
`parseA11y` / `a11yAttributes` / `serializeA11y` / `A11Y_DEFAULT`. The option set (`A11yState`) currently
cannot be extended without changes in the plugin.