For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/accessibility.md.

Accessibility

Screen readers read your app aloud and let people move through it by touch: VoiceOver on iPhone and TalkBack on Android. Lynx elements take attributes that tell the screen reader what each element is and what to say.

id, a11y-id and name

Three attributes name an element, and they're often confused:

AttributeWhat it's for
idThe element's unique name on the page. accessibility-elements and requestFocus('#id') use it
a11y-idA second name that only accessibility uses. accessibility-elements-a11y lists these, and several elements can share one
nameLets native code in the host app find the view. Accessibility doesn't use it

Use id unless you have a reason not to.

Label an element

<view
  [accessibility-element]="true"
  accessibility-traits="button"
  accessibility-label="Add to favorites"
  (bindtap)="favorite()"
>
  <image src="assets/heart.png" class="h-6 w-6" />
</view>
  • <text> and <image> are read by default. A <text> reads its own text, so most text needs nothing extra.
  • [accessibility-element]="true" makes an element one stop for the screen reader. Use it on a <view> that acts as a button or groups related content.
  • accessibility-label is what gets read. Give one to anything without readable text, such as an icon button.
  • accessibility-traits says what kind of thing it is, such as button, image, link or header. Note the plural: Lynx ignores accessibility-trait.
  • iOS takes several traits, separated by commas with no spaces, such as button,selected. Android reads only one.
  • A heading needs two attributes: accessibility-traits="header" for iOS, and accessibility-heading for Android, which reads only the none, image and button traits. Screen reader users skim a screen by jumping from heading to heading.
  • accessibility-value is a current value, read after the label, such as a slider's position.
  • accessibility-status is read before the label, on iOS and Android: accessibility-status="Unread" on a row labeled Inbox reads "Unread, Inbox".
  • An active routerLinkActive link is selected for you. LYNX_ELEMENTS adds the trait while its route is active, after the element's own traits. See Routing.

Every accessibility attribute, with the platforms that read it, is in the API reference.

Use ARIA attributes

<view role="button" aria-label="Add to favorites" (click)="favorite()">
  <image src="assets/heart.png" class="h-6 w-6" />
</view>

Lynx doesn't read ARIA, so on iOS and Android AngularLynx gives each ARIA attribute that has an equivalent as Lynx's own. That covers the attributes you'd write on the web, and what libraries such as Angular Aria and the CDK set. Bindings work too, such as [aria-label]="name()", [aria-checked]="on()" and [aria-expanded]="open()".

ARIALynxiOSAndroid
aria-labelaccessibility-label✅✅
aria-labelledbyaccessibility-label: the text of the elements it names✅✅
aria-hidden="true"accessibility-elements-hidden✅The element, not what's inside it
aria-modal="true"accessibility-exclusive-focus✅✅
aria-valuetextaccessibility-value✅✅ Android 11+
aria-checked, aria-pressed, aria-expandedaccessibility-value: "Checked", "On", "Pressed", "Expanded"…✅✅ Android 11+
aria-valuenow, aria-valuemin, aria-valuemaxaccessibility-value: "40%" for a progress bar, a meter or a slider, the number for other roles✅✅ Android 11+
aria-pressed="true"The selected trait too✅❌
aria-selected="true"The selected trait, or on Android accessibility-value "Selected"✅✅ Android 11+, as a value
aria-disabled="true"The disabled trait, or on Android accessibility-value "Disabled"✅✅ Android 11+, as a value
role="button"The button trait, and accessibility-element✅✅
role="img", role="image"The image trait, and accessibility-element✅✅
role="heading"The header trait, accessibility-heading and accessibility-element✅✅
role="link"The link trait, and accessibility-element✅One stop, not a link
role="searchbox"The search trait, and accessibility-element✅One stop, not a search box
role="tablist"The tabbar trait✅❌
role="switch", role="checkbox", menuitemcheckboxThe button trait, accessibility-role-description and accessibility-elementA buttonA switch or a checkbox
role="progressbar", role="meter"accessibility-role-description and accessibility-elementOne stopA progress bar
role="tab", radio, menuitemradio, menuitem, optionThe button trait, accessibility-role-description and accessibility-elementA buttonNamed: "Tab", "Radio button"…
role="slider", spinbutton, combobox, textboxaccessibility-role-description and accessibility-elementOne stopNamed: "Slider", "Combo box"…
role="none", role="presentation"accessibility-element="false"✅✅
<view
  role="button"
  aria-label="Details"
  [aria-expanded]="open()"
  (click)="open.set(!open())"
></view>

<text id="cart-total">{{ total() }}</text>
<view role="button" aria-labelledby="cart-total" (click)="checkout()"></view>

<view role="dialog" aria-modal="true">
  <text>{{ message() }}</text>
  <view role="button" aria-label="OK" (click)="close()"></view>
</view>

The first is a button whose value is "Collapsed" until it opens. The second is a button labeled by the total, which its label follows as total() changes. The dialog keeps the screen reader inside it while it's shown: aria-modal gives that, and role="dialog" gives nothing (see below).

  • A Lynx attribute you set yourself wins. With aria-label="Close" and accessibility-label="Close the dialog", the screen reader reads "Close the dialog", whichever you set first. Your own accessibility-value wins over a state's, and your own accessibility-traits replace the role's, and aria-selected, aria-pressed and aria-disabled add to whichever it has, as [lynxAccessibilityTraits] does.
  • aria-valuetext replaces the states' words. Without it, an element with several states says each, in turn: "Checked, Collapsed".
  • States are words, not the system's own states. Lynx 4.1 has no checked, pressed, expanded or range state on either platform, so VoiceOver and TalkBack read the word as the element's value, after its label. TalkBack doesn't say "checked" or "not checked" in the phone's language for them, and Android 7 to 10 don't read a value at all. The words are English unless you give your own.
  • aria-labelledby takes the text of each element it names, in its order, or that element's own aria-label. An element inside one is read by its own aria-label, or an image's alt, in place of its text, and one with aria-hidden="true" adds nothing, as in a browser, unless the element the id names is hidden itself: then all of it is read. A blank aria-label gives way to the text. It keeps up when that text changes, or when an element with the id appears later. It comes before the element's own aria-label, as in a browser, and the aria-label is the label while the ids name no text. An id with #, ., [, > or , in it can't be found, as Lynx looks ids up with its own selector.
  • An <img>'s aria-labelledby and aria-label come before its alt, as in a browser.
  • TalkBack hears aria-selected and aria-disabled only as a value. Lynx 4.1's Android reads one trait per element, and has no selected or disabled state (an open Lynx pull request, lynx-family/lynx#11000, would add them). So on Android they're words in the element's value, "Selected" or "Disabled", after any other state's: a disabled checked checkbox is "Checked, Disabled". VoiceOver reads both as traits.
  • There's no swipe to change a slider's value. Lynx 4.1 gives VoiceOver no increment or decrement, so role="slider" doesn't get the adjustable trait. Give accessibility-actions for that, as Dolan's slider does.
  • TalkBack still reaches what's inside an aria-hidden element, as it does with accessibility-elements-hidden. See Hide decoration.
  • VoiceOver takes each view directly inside a role="tablist" for a tab. Put it on the row whose children are the tabs.
  • The rest of ARIA does nothing, because Lynx has no equivalent: aria-live, aria-describedby, aria-current, aria-controls and the other relationship attributes, and the container roles such as listbox, menu and dialog. A role="dialog" isn't a stop of its own, so the screen reader doesn't read a label from its aria-label or aria-labelledby; its aria-modal works. Announce a change with LynxAccessibility.announce().
  • In the web preview, the browser reads the ARIA attributes themselves.

Say states in your app's language

The words for ARIA states and roles come from ACCESSIBILITY_WORDS, which is English unless you provide your own. Give a function to translate them with $localize: it runs as the app starts, after main.ts has loaded the translations.

src/app/app.config.ts
import {
  provideAccessibilityWords,
  provideRenderer,
} from '@blotch/angular-lynx';

export const appConfig = {
  providers: [
    provideRenderer(),
    provideAccessibilityWords(() => ({
      checked: $localize`:@@a11y.checked:Checked`,
      unchecked: $localize`:@@a11y.unchecked:Unchecked`,
      expanded: $localize`:@@a11y.expanded:Expanded`,
      collapsed: $localize`:@@a11y.collapsed:Collapsed`,
      percent: (percent: number) =>
        $localize`:@@a11y.percent:${percent}:percent:%`,
    })),
  ],
};
  • The words you leave out stay English. The full list is in the API reference.
  • Dolan's checkbox, switch and slider use the same words for their states, value and actions.
  • They're read once, as the app starts. To switch language, restart the app, as for most text.

Mark what's selected

When one of several options is chosen, such as Landscape or Portrait, the chosen one needs the selected trait. Bind it with [lynxAccessibilityTraits], which LYNX_ELEMENTS includes:

<view
  [accessibility-element]="true"
  accessibility-traits="button"
  accessibility-label="Landscape"
  [lynxAccessibilityTraits]="{ selected: orientation() === 'landscape' }"
  (bindtap)="orientation.set('landscape')"
>
  <text>Landscape</text>
</view>
  • Each trait that's true is added to the element's own traits, and taken away again when it turns false. VoiceOver reads the view as a selected button.
  • Don't write the list into accessibility-traits yourself. accessibility-traits="button,selected" works only on iOS. Android reads the attribute as one trait, so the list stops being a button there. With the binding, Android keeps button: it has no selected trait to add.
  • disabled works the same way, for an option that can't be chosen now. VoiceOver says it's dimmed.

A test finds the chosen option with getByRole('button', { name: 'Landscape', selected: true }).

Set the reading order

<view accessibility-elements="title,price,buy">
  <text id="price" [accessibility-element]="true">$12</text>
  <text id="title" [accessibility-element]="true">Blue mug</text>
  <view
    id="buy"
    [accessibility-element]="true"
    accessibility-traits="button"
    accessibility-label="Buy"
    (bindtap)="buy()"
  ></view>
</view>
  • Screen readers go top to bottom, then left to right, by default.
  • accessibility-elements lists child ids, separated by commas, in the order to read them. The example reads the title before the price.
  • Children not in the list can't be focused once a parent sets it.
  • accessibility-elements-a11y does the same with a11y-ids.

Hide decoration

<view [accessibility-elements-hidden]="true">
  <image src="assets/confetti.png" class="h-24 w-full" />
</view>

[accessibility-elements-hidden]="true", or aria-hidden="true", hides an element and everything inside it from VoiceOver.

On Android, Lynx 4.1 hides only the element itself. It leaves the children in TalkBack's tree, so hide each child that's an element of its own too:

  • With [accessibility-element]="false".
  • Or with role="presentation", on a child that doesn't set accessibility-element itself. A child's own accessibility-element="true" wins over the role, so change that one to false.

Keep focus inside a dialog

<overlay [visible]="open()">
  <view class="flex h-full w-full items-center justify-center bg-black/50">
    <view
      class="w-4/5 rounded-lg bg-background p-6"
      [accessibility-exclusive-focus]="true"
    >
      <text class="text-lg text-foreground">Delete this item?</text>
      <view
        [accessibility-element]="true"
        accessibility-traits="button"
        accessibility-label="Cancel"
        (bindtap)="open.set(false)"
      >
        <text>Cancel</text>
      </view>
    </view>
  </view>
</overlay>

With [accessibility-exclusive-focus]="true", the screen reader moves only between the elements inside it. People can't swipe out of the dialog to the page behind. See Dialogs and overlays.

Announce changes and move focus from code

Some changes don't move the screen reader, such as a cart count going up. Tell people about them with LynxAccessibility:

src/app/cart.ts
import { Component, inject, signal } from '@angular/core';
import { LYNX_ELEMENTS, LynxAccessibility } from '@blotch/angular-lynx';

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

  add(): void {
    this.count.update((n) => n + 1);
    this.#a11y.announce(`${this.count()} items in cart`).catch(() => {});
  }
}
  • announce(text) makes the screen reader speak, without moving focus.
  • requestFocus('#id') moves the screen reader to the element with that id, such as requestFocus('#total').
  • Both return a Promise that rejects where Lynx can't do it, such as in the web preview. The catch keeps that quiet.

The signatures are in the API reference.

Check it in unit tests

The testing library's queries read these attributes, so a test finds an element the way a screen reader does:

src/app/cart.test.ts
const { getByRole } = await render(Cart);

fireEvent.tap(getByRole('button', { name: 'Add to cart' }));

getByRole finds a <view> only with [accessibility-element]="true", so a missing one fails the test. See *ByRole and *ByAccessibilityLabel.

Follow the user's display settings

Reduce Motion, Reduce Transparency and Increase Contrast are signals on LynxAccessibilitySettings:

src/app/banner.ts
import { Component, computed, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxAccessibilitySettings } from '@blotch/angular-lynx';

@Component({
  selector: 'app-banner',
  imports: [LYNX_ELEMENTS],
  template: `<view [style.transition]="transition()">…</view>`,
})
export class Banner {
  readonly #settings = inject(LynxAccessibilitySettings);

  // Slide in, unless the user asked for less motion.
  protected readonly transition = computed(() =>
    this.#settings.reduceMotion() ? 'none' : 'transform 300ms ease-out',
  );
}

The apps ng build --platform makes send the settings, and the web preview reads the browser's. See LynxAccessibilitySettings for where each comes from. The Glass component follows them on its own.

Follow the phone's text size

Apps from ng build --platform follow the text size the person chose, and change while the app is open:

  • iOS: Dynamic Type, in Settings → Display & Brightness → Text Size. The larger sizes are under Accessibility → Display & Text Size.
  • Android: the font size, in Settings → Display → Font size.

The page's root font size grows by the person's scale, so everything sized in rem grows with it: Tailwind's text-base, h-12 and p-4, and the Dolan UI components. A size in px stays as written, for the few labels that mustn't grow:

<text class="text-base">Grows with the phone's text</text>
<text style="font-size: 12px">Stays at 12px</text>

A <text> with no font size of its own takes its parent's. That's the page's unless an element above it sets one, so it grows too. It doesn't if that size is in px: under a <view> with font-size: 18px, it stays 18px.

To change a layout that can't simply grow, such as a row that puts its label under the icon at a large size, read textScale():

src/app/row.ts
readonly #settings = inject(LynxAccessibilitySettings);

// 1 at the default size, about 3.1 at iOS's largest.
protected readonly stacked = computed(() => this.#settings.textScale() > 1.5);

If a screen isn't ready for the largest sizes, cap the scale, or turn it off, with textScaling in the build target's options in angular.json:

angular.json
"options": {
  "textScaling": { "max": 1.6 }
}

"textScaling": false keeps the text at its default size. The web preview and Lynx Explorer stay at the default size.

Check a screen at the largest sizes: in the iOS Simulator, with Xcode's Environment Overrides or xcrun simctl ui booted content_size accessibility-extra-extra-extra-large, and on Android with adb shell settings put system font_scale 2.0. Look for anything with a fixed height in px that the text now overflows.

Test with a screen reader

On an iPhone:

  1. Open Settings → Accessibility → VoiceOver and turn it on.
  2. Swipe right or left to move between elements. Double-tap anywhere to tap the selected one.
  3. To toggle it quickly, set Settings → Accessibility → Accessibility Shortcut to VoiceOver, then triple-click the side button.

VoiceOver doesn't run in the iOS Simulator, the virtual iPhone on your Mac. Instead, open Accessibility Inspector from Xcode's Xcode → Open Developer Tool menu and point it at the Simulator. It shows the label and traits of each element you hover.

On Android:

  1. Open Settings → Accessibility → TalkBack and turn it on. On some phones, it's under Installed apps or Downloaded apps in that menu.
  2. Swipe right or left to move between elements. Double-tap to tap the selected one.

TalkBack also runs in the Android emulator, the virtual Android phone on your computer. Drag with the mouse to swipe. If its Settings has no TalkBack, install Android Accessibility Suite from the Play Store, which needs an emulator image with Google Play.

You can test either way in Lynx Explorer or in your own app. AngularLynx turns on Lynx's accessibility support in every build, so there's nothing to enable.