Part 2 of a series on Angular accessibility. Part 1 introduced Openbook, a fictional demo app that starts out deliberately inaccessible.
In Part 1, I read through Openbook's code and listed what I expected to go wrong. This post starts fixing it, beginning with the foundation: the HTML itself. Most of the changes are small, and they make the biggest difference to keyboard and screen reader users, because everything else builds on them.
Repo: openbook-angular-a11y
Before: post-01-baseline
After: post-02-after
As in Part 1, I haven't run an automated scanner or a screen reader against this version. The changes below follow from how native HTML elements and ARIA attributes are defined to behave. I'll point out where behavior is worth checking yourself.
What we're fixing
| ID | Problem in the baseline | Fix in this post |
|---|---|---|
| A01 | No landmarks | <header>, <nav>, <main> |
| A02 | No skip link | "Skip to main content" link |
| A03 | Navigation built from clickable divs | Real links with routerLink |
| A04 | Icon buttons with no accessible name | aria-label, hidden decorative SVGs |
| A05 | Skipped and misused heading levels | h1 then h2 |
| A19 | No lang on the page | lang="en" |
1. Landmarks: give the page a map
Before, the whole shell was divs:
<div class="topbar"> <div class="logo">Openbook</div> ... </div> <div class="content"> <router-outlet /> </div> After:
<header class="topbar"> <span class="logo">Openbook</span> <nav class="nav" aria-label="Main"> ... </nav> ... </header> <main #main id="main" class="content" tabindex="-1"> <router-outlet /> </main> <header>, <nav> and <main> are landmarks. Screen readers can list them and jump straight to the one the user wants, instead of reading through the page from the top. The aria-label="Main" on the nav matters once a page has more than one navigation region, because it tells them apart.
The tabindex="-1" on <main> doesn't put it in the Tab order. It only allows us to move focus there from code, which we need for the next step.
2. A skip link, and an Angular gotcha
Keyboard users have to Tab through every navigation item on every page before reaching the content. A skip link lets them jump past it:
<a class="skip-link" href="#main" (click)="skipToMain($event, main)"> Skip to main content </a> skipToMain(event: Event, target: HTMLElement) { event.preventDefault(); target.focus(); } .skip-link { position: absolute; left: -9999px; top: 0; z-index: 100; background: #fff; color: #000; padding: 8px 12px; } .skip-link:focus { left: 8px; top: 8px; } The link is off-screen until it receives focus, then it appears in the top-left corner.
Why not just a plain href="#main"? Openbook's index.html has <base href="/">, which Angular apps use for routing. With that tag present, a bare #main link resolves against the base URL, so the browser can treat it as a navigation to /#main instead of a jump within the page. In an app like this one, that can trigger a route change. Handling the click ourselves and focusing <main> avoids the problem. I'd suggest trying the link in your own app, since behavior depends on your routing setup.
3. Real links instead of clickable divs
This was the most serious baseline flaw. Before:
<div class="nav-item" (click)="go('/accounts')">Accounts</div> A div isn't focusable and doesn't respond to Enter, so it's out of reach for keyboard users. It also tells a screen reader nothing about being navigation. After:
<a class="nav-item" routerLink="/accounts" routerLinkActive="active" ariaCurrentWhenActive="page">Accounts</a> A native <a> with an href (which routerLink provides) is focusable, activates with Enter, can be opened in a new tab, and is announced as a link. routerLinkActive adds a CSS class to the current page's link, and ariaCurrentWhenActive="page" sets aria-current="page" so assistive technology knows which link is current.
I styled the active link as bold and underlined, not just a different color, so the state doesn't depend on color alone.
Check: I believe ariaCurrentWhenActive is available on routerLinkActive in recent Angular versions, but confirm it against the Angular documentation for the version you use.
4. Name the icon buttons
Before:
<button class="icon-btn" (click)="go('/accounts')"> <svg width="20" height="20" viewBox="0 0 24 24"><path d="..."/></svg> </button> A button with only an SVG inside has no text, so there's nothing for a screen reader to announce except "button". After:
<button type="button" class="icon-btn" aria-label="Notifications"> <svg aria-hidden="true" focusable="false" width="20" height="20" viewBox="0 0 24 24"> <path d="..."/> </svg> </button> Two small changes: aria-label gives the button its accessible name, and aria-hidden="true" on the SVG hides the decorative drawing so it isn't announced as an extra, unnamed graphic. I also added type="button" as a good habit. It stops a button from accidentally submitting a form if it's ever placed inside one.
One honest caveat: in the baseline, these buttons navigated to Accounts and Login, which would have made accurate labels misleading. So I removed that behavior. They're now named placeholders until later posts add real notifications and a settings dialog. A named button that does nothing is still a flaw, and I'm flagging it in the repo's known-issues.md rather than hiding it.
5. Headings: one h1, then a logical outline
Headings are how many screen reader users scan a page. In the baseline, Login used an h3 as its only heading, and Accounts jumped from h1 to h4. The fix is mostly renaming:
<!-- login.html --> <h1>Welcome back</h1> <!-- accounts.html --> <h1>Accounts</h1> ... <h2>{{ a.name }}</h2> ... <h2>Recent transactions</h2> A useful rule: choose heading levels for structure, not for how they look. If the default size is wrong, change it with CSS, not by picking a different level. That's why the stylesheet now sets sizes for h2 and the card's h1.
6. Declare the page language
<html lang="en"> One attribute, and it tells screen readers which language rules to use for pronunciation. I'd left it out of the baseline by mistake, so I'm counting it as a planted flaw and fixing it here.
What's still broken (on purpose)
This post only fixes structure. These are still in the app:
- Inputs with no labels and
divsubmit buttons (Part 3) - No visible focus indicator, and the page title never changes (Part 4)
- The silent toast message (Part 5)
- The
div-based transactions "table" (Part 7) - Low color contrast (Part 8)
The repo's docs/known-issues.md tracks every item and which post fixes it.
Try it yourself
- Clone the repo and check out
post-02-after. - Run
npm installandng serve. - Put your mouse aside and press Tab. Does the skip link appear first? Can you reach all three navigation links?
- Press Enter on the skip link. Where does focus go?
- If you use a screen reader, open its landmarks and headings lists on each page.
Even before fixing focus styles, these checks show how much a handful of correct elements changes the experience.
Next
In Part 3, we fix the forms: real labels, accessible error messages, and buttons that submit.
Which of these fixes do you most often find missing in the Angular apps you work on? Tell me in the comments.
