Accessible Website Navigation: Links, Buttons and Focus
Build navigation with clear links, useful buttons and predictable keyboard behaviour.
A website menu can look finished in a design review and still be difficult to use.
The dropdown opens with a mouse, but not a keyboard. A control looks like a link but only expands a panel. Focus disappears against the header background. On a phone, the submenu covers the next navigation item.
For a service business, these problems can interrupt a straightforward task: finding the right service and deciding what to do next.
Accessible navigation begins with clear choices and predictable controls. The implementation should communicate what each element does, preserve a useful reading order and make the user’s current position visible.
This tutorial walks through a small disclosure-navigation pattern for a business website. The example is intentionally limited: one expandable service list, ordinary destination links and no modal mobile drawer.
Start With the Task Behind the Navigation
Before writing the component, identify what visitors need to reach.
A business website might need routes to services, project examples, company information and contact details. Within services, visitors should see names they can recognise without already knowing the company’s internal terminology.
A technically sound component cannot fix confusing labels.
For example, a customer looking for website design may not immediately understand a category called “Digital Experiences.” That phrase could remain part of the brand language, but the navigation still needs to explain the available services.
This is relevant to Bizfront’s approach to website design, which starts with understanding the business and what customers need to hear.
The developer’s job is to preserve that clarity in the interface.
Write the expected journey before implementing it:
A visitor reaches the primary navigation, opens the service list, identifies the relevant service and follows its link. They can also leave the list and continue through the page without getting trapped.
That journey gives you something concrete to build and test.
Use Links for Destinations and Buttons for Actions
A link takes someone to a destination. A disclosure button changes whether additional content is visible.
Keep those responsibilities separate.
For a service category that also has an overview page, provide a link to the overview and an adjacent button for showing the individual service links.
Avoid making one control navigate on some interactions and expand on others. That behaviour can be difficult to discover and explain.
Use native elements:
- An anchor with an
hreffor navigation. - A button with
type="button"for opening and closing the list. - A navigation landmark around the related links.
- Lists to express the grouping of destinations.
The word “menu” in everyday conversation does not mean the component needs role="menu".
W3C’s disclosure-navigation example explains why ordinary website navigation typically does not need the specialised interaction model associated with ARIA menus.
Start with the simpler pattern that matches the task.
Build a Useful HTML Baseline
The following markup uses fictional local paths. Replace them with real destinations in your website.
The service links are initially visible, and the disclosure button is initially hidden. If JavaScript does not initialise, visitors can still use the links.
<nav aria-label="Primary" class="site-nav">
<ul class="primary-links">
<li>
<a href="/">Home</a>
</li>
<li class="service-group">
<div class="service-heading">
<a href="/services/">Services</a>
<button
type="button"
id="services-toggle"
aria-expanded="true"
aria-controls="service-links"
hidden
>
Service links
<span aria-hidden="true">▾</span>
</button>
</div>
<ul id="service-links">
<li>
<a href="/services/website-design/">
Website design
</a>
</li>
<li>
<a href="/services/content-marketing/">
Content marketing
</a>
</li>
<li>
<a href="/services/search-optimization/">
Search optimization
</a>
</li>
</ul>
</li>
<li>
<a href="/work/">Our work</a>
</li>
<li>
<a href="/contact/">Contact</a>
</li>
</ul>
</nav>
The visible button text identifies the controlled content. Its expanded state tells assistive technology whether that content is currently open.
The arrow is decorative, so it is hidden from assistive technology.
If you identify the current destination with aria-current="page", assign it according to the actual page being displayed. Do not update it merely because someone clicked a link when navigation has not yet completed.
Also keep IDs unique if you introduce more than one disclosure.
Keep State and Visibility Together
The button’s aria-expanded value and the list’s actual visibility must agree.
Use one function to update both. That reduces the chance of later edits changing the visual state while leaving the accessibility state behind.
Place this script after the markup or load it with defer.
const group = document.querySelector(".service-group");
const toggle = document.getElementById("services-toggle");
const panel = document.getElementById("service-links");
if (group && toggle && panel) {
function isOpen() {
return toggle.getAttribute("aria-expanded") === "true";
}
function setOpen(open, { restoreFocus = false } = {}) {
// Move focus before hiding a panel that contains it.
if (
!open &&
(restoreFocus || panel.contains(document.activeElement))
) {
toggle.focus();
}
panel.hidden = !open;
toggle.setAttribute("aria-expanded", String(open));
}
toggle.addEventListener("click", () => {
setOpen(!isOpen());
});
group.addEventListener("keydown", (event) => {
if (event.key === "Escape" && isOpen()) {
event.preventDefault();
setOpen(false, { restoreFocus: true });
}
});
group.addEventListener("focusout", (event) => {
const next = event.relatedTarget;
if (!next || !group.contains(next)) {
setOpen(false);
}
});
// Enable the disclosure only after wiring its behaviour.
toggle.hidden = false;
setOpen(false);
}
Opening the list keeps focus on the button. Pressing Tab then reaches the first service link.
Escape closes the open list and returns focus to the controlling button. Moving focus outside the service group closes it without deliberately moving focus away from the user’s next destination.
This example does not close on every outside pointer click. That is a separate interaction decision; if added, test that it does not interrupt link activation or leave focus inside hidden content.
Preserve Ordinary Keyboard Behaviour
Native links and buttons already provide useful keyboard behaviour.
Avoid adding handlers that recreate activation unnecessarily. A native button supports keyboard activation without a separate handler for each activation key.
The example keeps ordinary Tab and Shift+Tab navigation. It does not implement arrow-key navigation or a roving tabindex system.
That choice keeps the component close to a normal list of links.
Do not add positive tabindex values to rearrange the sequence. If the navigation order is confusing, review the document order and layout.
Also avoid trapping focus inside an ordinary dropdown. Someone should be able to move through the service links and continue to the next navigation item.
A modal navigation drawer is a different component. If your mobile design blocks interaction with the rest of the page, it needs a deliberately designed focus and dismissal model. Do not assume this small disclosure example covers that behaviour.
Choose the pattern first, then implement its complete interaction.
Make Focus Easy to See
Keyboard users need to see which control will respond when they activate it.
W3C’s Focus Visible guidance explains the purpose of a visible keyboard focus indicator. Treat it as part of the design rather than a browser detail to remove.
The following CSS gives the example a simple layout and focus outline.
.site-nav {
color: #142c3e;
background: #ffffff;
}
.site-nav [hidden] {
display: none !important;
}
.primary-links,
#service-links {
list-style: none;
margin: 0;
padding: 0;
}
.primary-links {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
gap: 0.5rem 1rem;
}
.service-heading {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.25rem;
}
.site-nav a,
.site-nav button {
display: inline-flex;
align-items: center;
min-block-size: 2.75rem;
padding: 0.5rem 0.75rem;
font: inherit;
color: inherit;
}
.site-nav button {
gap: 0.5rem;
background: transparent;
border: 1px solid currentColor;
border-radius: 0.25rem;
cursor: pointer;
}
.site-nav :is(a, button):focus-visible {
outline: 3px solid #142c3e;
outline-offset: 3px;
}
#service-links {
padding-inline-start: 1rem;
}
#services-toggle[aria-expanded="true"] span {
transform: rotate(180deg);
}
@media (max-width: 40rem) {
.primary-links {
flex-direction: column;
align-items: stretch;
}
}
@media (forced-colors: active) {
.site-nav :is(a, button):focus-visible {
outline-color: Highlight;
}
}
The expanded list remains in normal document flow. This avoids introducing an overlapping panel in the initial example.
The focus colour is chosen for the white background shown here. Review it again if the design changes.
Check that outlines are not clipped by a parent’s overflow settings or covered by another component. Do not add outline: none elsewhere without understanding what replaces the visible indication.
These styles are a starting point, not proof of WCAG conformance.
Test the Complete Keyboard Journey
Run a manual test before reviewing only the visual result.
Start before the navigation and use Tab to reach the first link. Continue to the Services overview link and then the disclosure button.
Open the list using the keyboard. Confirm that focus remains visible and the next Tab reaches the first service.
Continue through every service link and into the following navigation item. The list should close after focus leaves the group.
Repeat the journey in reverse with Shift+Tab.
Then open the list, focus a service link and press Escape. Confirm that the list closes and focus returns to the button.
Test a collapsed list as well. Its hidden links should not remain in the Tab sequence.
Finally, disable JavaScript and reload. The fallback links should remain available, with the inactive disclosure button hidden.
Record what happened rather than simply marking the menu “accessible.”
Check Touch, Zoom and Assistive Technology
Keyboard testing is necessary, but it does not cover every interaction.
On a touch device, confirm that the overview link and disclosure button can be selected separately. Check that the controls do not require hovering to reveal essential destinations.
Increase text size and browser zoom. Look for clipped labels, overlapping controls and horizontal scrolling caused by fixed dimensions.
Try longer service names. A component that works with “SEO” may fail when the content changes to “Search Engine Optimization.”
With a screen reader, check whether the navigation landmark has a useful name, the control is announced as a button and its expanded state changes correctly.
Confirm that collapsed service links are not exposed as available destinations.
Test combinations relevant to your audience and record the browser and assistive technology used. W3C explicitly cautions that its own examples require testing before production use; a copied pattern does not remove that responsibility.
Automated checks can help identify some markup problems. They cannot tell you whether the complete journey is understandable.
Protect Navigation When the Website Changes
Navigation rarely stays unchanged.
A new service arrives. A team member renames a page. A design update introduces a sticky header. Each change can affect the component.
Keep a short regression checklist with the implementation:
- Every destination is correct.
- Labels remain understandable.
- IDs and control relationships remain unique.
- Expanded state matches visibility.
- Focus remains visible.
- Hidden links are not keyboard reachable.
- Escape and ordinary Tab navigation still work.
- Long labels and narrow layouts remain usable.
- The fallback remains available if enhancement fails.
If you move the pattern into a framework, preserve those behaviours across rendering and route changes. Clean up listeners where necessary and avoid collapsing a panel around focused content without a deliberate focus destination.
A service menu is small, but it is part of the customer’s route through the business.
Build Navigation Around a Clear Next Step
Accessible navigation combines understandable content with predictable implementation.
Use links for destinations, buttons for disclosure and visible focus throughout the journey. Keep state accurate, support a useful fallback and test the behaviour beyond the happy path.
For a business planning a new site, these decisions belong alongside page structure and service messaging. Planning a clearer business website with Bizfront starts with what customers need to understand and do.
A useful final test is practical: can someone find the relevant service and continue through the website using the interaction method they depend on?
That is the experience the component needs to support.
Top comments (0)