Sub topic 2
Showing the Current Page with `aria-current`
Assume basic HTML and CSS, link and list markup, JavaScript events, responsive design, and media queries. This chapter uses those skills to connect navigation state, keyboard behavior, and responsive layout.
Showing the Current Page with `aria-current`
Use aria-current="page" on the link for the page the visitor is viewing. This gives assistive technology a reliable state instead of relying only on color or an underline. Add it to one link in the relevant navigation group, not to every link.
<nav aria-label="Primary">
<ul>
<li><a href="/" aria-current="page">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/pricing">Pricing</a></li>
</ul>
</nav>Style the same state visually:
nav a[aria-current="page"] {
font-weight: 700;
text-decoration: underline;
}Keyboard Access and Visible Focus
Every link and button must be reachable with the Tab key. Never remove the browser’s focus outline without replacing it. :focus-visible shows a strong indicator mainly for keyboard users.
nav a:focus-visible,
nav button:focus-visible {
outline: 3px solid #1a5fd0;
outline-offset: 2px;
}Responsive Navigation and Touch Targets
On small screens, reduce columns or replace a wide menu with a button-controlled panel. Keep interactive targets large enough to tap, with padding around the text. Test at narrow widths and with zoom enabled.
Submenus as Disclosure Buttons
A disclosure button reveals or hides a submenu. Its aria-expanded value must match the panel’s visibility, and aria-controls must identify that panel.
<button type="button" aria-expanded="false" aria-controls="products-panel">
Products
</button>
<div id="products-panel" hidden>
<a href="/platform">Platform</a>
<a href="/security">Security</a>
</div>Use a button when the label opens content. Use a link when the label navigates to a page.
When a Mega Menu Is the Right Choice
Choose a mega menu when a site has many related destinations that benefit from visible grouping, such as an enterprise product catalog. A simple menu is better for a small set of destinations. A mega menu adds interaction and testing cost, so do not use it only for visual effect.
Structuring and Laying Out Mega Menu Content
Group links under meaningful headings. Use lists for each group and a responsive grid for layout. On small screens, stack the groups or use separate disclosures.
Exercise
Which attribute identifies the page currently being viewed?
Show answer
Add aria-current="page" to that page's navigation link.