> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Accessibility

`LynxAccessibility` speaks to screen readers from code, the `accessibility-*` attributes describe elements to them, `LynxAccessibilityTraits` adds traits such as `selected` from a binding, `LynxAccessibilitySettings` reads the user's display settings, and `provideAccessibilityWords()` gives the words ARIA states are said in. `import { LynxAccessibility, LynxAccessibilitySettings, LynxAccessibilityTraits, provideAccessibilityWords } from '@blotch/angular-lynx';`

## Usage

```typescript title="src/app/cart-button.ts"
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxAccessibility } from '@blotch/angular-lynx';

@Component({
  selector: 'app-cart-button',
  imports: [LYNX_ELEMENTS],
  template: `
    <view
      accessibility-element="true"
      accessibility-label="Add to cart"
      accessibility-traits="button"
      (bindtap)="add()"
    >
      <text>+</text>
    </view>
  `,
})
export class CartButton {
  readonly #a11y = inject(LynxAccessibility);

  add(): void {
    // Add the item here.
  }

  async notify(message: string): Promise<void> {
    try {
      await this.#a11y.announce(message);
    } catch {
      // Announcements aren't available on this thread or platform.
    }
  }
}
```

The screen reader is VoiceOver on iOS and TalkBack on Android.

## API

### `LynxAccessibility`

```typescript
@Injectable({ providedIn: 'root' })
class LynxAccessibility {}
```

Imperative screen reader control, for changes that the attributes below can't express.

Both methods work from event handlers.

### `LynxAccessibility.announce()`

```typescript
announce(content: string): Promise<void>;
```

Makes the screen reader speak `content` without moving focus. Use it for results that don't move focus, such as "Saved" or a finished upload.

- **Resolves** once Lynx accepts the announcement.
- **Rejects** when Lynx's announce API isn't available, such as in the web preview.
- **From an event handler,** the call runs on the [background thread](/guide/glossary.md#background-thread), the only one with Lynx's announce API. AngularLynx sends it there for you.

### `LynxAccessibility.requestFocus()`

```typescript
requestFocus(selector: string): Promise<void>;
```

Moves the screen reader's focus to the element that matches `selector`. Give that element `accessibility-element="true"`.

- **`selector`:** use an ID selector such as `'#confirmation'`, which matches the element's `id`. Other selectors aren't reliable.
- **Rejects** when no element matches, or with the Lynx error code when the element can't take focus.

### `LynxAccessibilityTraits`

```typescript
@Directive({ selector: '[lynxAccessibilityTraits]' })
class LynxAccessibilityTraits {
  readonly lynxAccessibilityTraits: InputSignal<
    AccessibilityTraitStates | null | undefined
  >;
}
```

Adds traits to the element's own `accessibility-traits` while a binding says so. Use it for state that changes, such as `selected` on the chosen one of several options, or `disabled`. It's part of `LYNX_ELEMENTS`, so any component that imports `LYNX_ELEMENTS` can bind it.

```angular-html
<view
  [accessibility-element]="true"
  accessibility-traits="button"
  [accessibility-label]="label()"
  [lynxAccessibilityTraits]="{ selected: selected() }"
  (bindtap)="chosen.emit()"
>
  <text>{{ label() }}</text>
</view>
```

- **A trait that's `true` is added** after the element's own: `button` reads `button,selected` on iOS.
- **A trait that turns `false`, or that the map leaves out, is taken away.** Only the traits the binding added are: the element's own `accessibility-traits` stay.
- **Android keeps the element's own trait.** It reads a single trait and has no selected or disabled trait, so a list would read as no trait at all. Writing `accessibility-traits="button,selected"` yourself stops the element being a button there; this doesn't.
- **On a component's own host,** which its template can't bind, call `setAccessibilityTrait(trait, on)` on the host's [`BaseLynxElement`](/api/angular-lynx/elements/index.md#baselynxelement) instead. It merges the trait the same way.

### `LynxAccessibilitySettings`

```typescript
@Injectable({ providedIn: 'root' })
class LynxAccessibilitySettings {
  readonly reduceMotion: Signal<boolean>;
  readonly reduceTransparency: Signal<boolean>;
  readonly increaseContrast: Signal<boolean>;
  readonly textScale: Signal<number>;
}
```

The user's display settings, as signals that update when the user changes one.

```typescript title="src/app/drawer.ts"
readonly #settings = inject(LynxAccessibilitySettings);

// Jump into place instead of sliding when the user asked for less motion.
readonly duration = computed(() => (this.#settings.reduceMotion() ? 0 : 300));
```

- **`reduceMotion()`:** the user asked for less motion. Replace slides and bounces with a fade or an instant change.
- **`reduceTransparency()`:** the user asked for less transparency. Draw blurred and translucent surfaces opaque.
- **`increaseContrast()`:** the user asked for more contrast. Strengthen edges and use full-strength text colors.
- **`textScale()`:** how much larger than the system's default the user's text is. It's `1` at the default, `1.5` for text half as large again, and below `1` at iOS's smaller sizes. The app's text already follows it (see [Follow the phone's text size](/guide/accessibility.md#follow-the-phones-text-size)), so read it only to change a layout that can't simply grow.

Lynx has no API for these, so they come from the [host app](/guide/glossary.md#host-app), as the theme does, in the `reduceMotion`, `reduceTransparency`, `increaseContrast` and `textScale` [global props](/guide/embedding/host-data.md). Each switch is off unless it's `true`, and `textScale` is `1` unless it's a positive number.

| Where the app runs                                | Where the settings come from                                                                                                                      |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Apps from `ng build --platform`, iOS              | Reduce Motion, Reduce Transparency, Increase Contrast and Dynamic Type's text size, sent again when they change                                   |
| Apps from `ng build --platform`, Android          | Remove animations, contrast above standard (Android 14) or high contrast text (Android 16), and the font size. Android has no Reduce Transparency |
| [Web preview](/guide/glossary.md#web-preview)     | The browser's `prefers-reduced-motion`, `prefers-reduced-transparency` and `prefers-contrast: more`. `textScale()` is `1`                         |
| [Lynx Explorer](/guide/glossary.md#lynx-explorer) | None: add them to the bundle URL to try them, such as `?reduceMotion=true` or `?textScale=1.5` (which sets the signal, not the text)              |

iOS 27's Liquid Glass setting (clear or tinted glass) has no public API, so it isn't here. iOS's own glass follows it.

### `ACCESSIBILITY_WORDS`

```typescript
const ACCESSIBILITY_WORDS: InjectionToken<AccessibilityWords>;
```

The words screen readers say for the [ARIA attributes](#aria-attributes) that Lynx has no state or trait for, which AngularLynx gives as text: an `accessibility-value` such as "Checked", and on Android an `accessibility-role-description` such as "Tab". [Dolan](/dolan/index.md)'s checkbox, switch and slider say theirs in the same words. English unless the app provides its own. The renderer reads them once, as the app starts.

### `provideAccessibilityWords()`

```typescript
function provideAccessibilityWords(
  words: Partial<AccessibilityWords> | (() => Partial<AccessibilityWords>),
): EnvironmentProviders;
```

Provides `ACCESSIBILITY_WORDS`: the words given replace the English ones, and the rest stay English. A function runs in an injection context as the app starts, so `$localize` in it sees the translations main.ts loaded. See [Say states in your app's language](/guide/accessibility.md#say-states-in-your-apps-language).

## Attributes

Every Lynx element accepts these attributes. Set them as static attributes, or bind them with `[accessibility-label]="label()"`, which type-checks.

| Attribute                       | Type       | Default  | Description                                                                                                                |
| ------------------------------- | ---------- | -------- | -------------------------------------------------------------------------------------------------------------------------- |
| `accessibility-element`         | `boolean`  |          | Makes the element a stop for the screen reader.                                                                            |
| `accessibility-label`           | `string`   |          | The text the screen reader reads. Required when the element has no readable text.                                          |
| `accessibility-traits`          | See below  | `'none'` | The element's role, such as `'button'` or `'image'`.                                                                       |
| `accessibility-value`           | `string`   |          | A current value read after the label, such as a slider's position.                                                         |
| `accessibility-actions`         | `string[]` |          | Custom actions the screen reader offers for the element.                                                                   |
| `accessibility-elements`        | `string`   |          | Comma-separated `id`s of child elements, in the order the screen reader visits them. Children not listed can't take focus. |
| `accessibility-elements-hidden` | `boolean`  | `false`  | Hides the element and everything inside it from the screen reader.                                                         |
| `accessibility-exclusive-focus` | `boolean`  | `false`  | Keeps the screen reader's focus inside this element, for example in a modal.                                               |
| `a11y-id`                       | `string`   |          | An accessibility identifier, separate from `id`. Lynx's `accessibility-elements-a11y` attribute orders children by it.     |

Some are read on one platform only:

| Attribute                              | Type      | Default | Platforms    | Description                                                                                                                                                                                         |
| -------------------------------------- | --------- | ------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `accessibility-status`                 | `string`  |         | iOS, Android | A state read before the label, such as `'Unread'`: the screen reader reads `'Unread, Inbox'`. Give a `<text>` with a status an `accessibility-label`: iOS then reads only the status, not the text. |
| `accessibility-heading`                | `boolean` | `false` | Android 9+   | Makes the element a heading, which TalkBack can jump between. On iOS, use the `header` trait: Android ignores it, so give a heading both.                                                           |
| `accessibility-role-description`       | `string`  |         | Android      | `'button'`, `'switch'`, `'checkbox'`, `'image'` or `'progressbar'` makes TalkBack call the element that kind of control. TalkBack reads any other text in place of the element's kind.              |
| `accessibility-enable-tap`             | `boolean` | `false` | Android      | TalkBack's double tap sends the element a `tap`.                                                                                                                                                    |
| `accessibility-auto-scroll-if-focused` | `boolean` | `false` | iOS          | Scrolls the element into view when code moves VoiceOver's focus to it.                                                                                                                              |
| `android-accessibility-keep-focused`   | `boolean` | `false` | Android      | Keeps TalkBack's focus on the element when the elements around it change.                                                                                                                           |

`accessibility-traits` takes one of `'text'`, `'image'`, `'button'`, `'link'`, `'header'`, `'search'`, `'selected'`, `'playable'`, `'keyboard'`, `'summary'`, `'disabled'`, `'updating'`, `'adjustable'`, `'tabbar'` or `'none'`.

- **iOS also takes several,** separated by commas with no spaces, such as `'button,selected'`.
- **Android reads a single `'none'`, `'image'` or `'button'`,** and ignores the rest.
- **HarmonyOS, like Android, reads a single trait:** `'button'`, `'image'` or `'text'`.
- **An active [`routerLinkActive`](/api/angular-lynx/routing/index.md#lynxrouterlinkactive) element** gets `selected` added to its own traits. To add one from your own state, use [`LynxAccessibilityTraits`](#lynxaccessibilitytraits).

Write the plural: Lynx ignores `accessibility-trait`. `ng update` renames it in apps written before 22.2.3, when `LYNX_ELEMENTS` declared the singular.

## ARIA attributes

On iOS and Android, `aria-label`, `aria-labelledby`, `aria-hidden`, `aria-modal`, `aria-valuetext`, `aria-checked`, `aria-pressed`, `aria-expanded`, `aria-valuenow` (with `aria-valuemin` and `aria-valuemax`), `aria-selected`, `aria-disabled` and `role` give the attributes above, the states in the words of [`ACCESSIBILITY_WORDS`](#accessibility_words). The rest of ARIA does nothing. [Use ARIA attributes](/guide/accessibility.md#use-aria-attributes) has the table. An attribute above that you set yourself wins over the one ARIA gives.

## Types

### `AccessibilityTrait`

```typescript
type AccessibilityTrait =
  | 'text'
  | 'image'
  | 'button'
  | 'link'
  | 'header'
  | 'search'
  | 'selected'
  | 'playable'
  | 'keyboard'
  | 'summary'
  | 'disabled'
  | 'updating'
  | 'adjustable'
  | 'tabbar'
  | 'none';
```

One trait of `accessibility-traits`.

### `AccessibilityTraitStates`

```typescript
type AccessibilityTraitStates = Partial<
  Record<Exclude<AccessibilityTrait, 'none'>, boolean>
>;
```

What `[lynxAccessibilityTraits]` takes: each trait to add, by name, with whether to add it now.

### `AccessibilityWords`

```typescript
type AccessibilityWords = {
  checked: string; // 'Checked'
  unchecked: string; // 'Unchecked'
  partiallyChecked: string; // 'Partially checked'
  on: string; // 'On', aria-checked on a switch
  off: string; // 'Off'
  pressed: string; // 'Pressed'
  notPressed: string; // 'Not pressed'
  partiallyPressed: string; // 'Partially pressed'
  expanded: string; // 'Expanded'
  collapsed: string; // 'Collapsed'
  selected: string; // 'Selected', aria-selected on Android
  disabled: string; // 'Disabled', aria-disabled on Android
  percent: (percent: number) => string; // '40%'
  increase: string; // 'Increase', Dolan's slider's action
  decrease: string; // 'Decrease'
  tab: string; // 'Tab', TalkBack's name for role="tab"
  radioButton: string; // 'Radio button': radio, menuitemradio
  menuItem: string; // 'Menu item'
  option: string; // 'Option'
  slider: string; // 'Slider'
  spinButton: string; // 'Spin button'
  comboBox: string; // 'Combo box'
  textField: string; // 'Text field': textbox
};
```

The words of `ACCESSIBILITY_WORDS`, with their English.

## Related

- [Accessibility](/guide/accessibility.md): labeling, grouping and focus traps.
- [Elements](/api/angular-lynx/elements/index.md#attributes-on-every-element): the other attributes every element accepts.
- [Lynx accessibility docs](https://lynxjs.org/guide/inclusion/accessibility.html)
