You’re on your phone, halfway through a train journey, trying to find the returns policy for a shop you bought from last week. The header holds a logo, maybe a search icon, and a small button with three stacked lines. You tap it, a panel slides in with the full site navigation, and you spot Returns in two seconds. That small control did more work than anything else on the page.
It’s also one of the easiest things to build badly. A button that opens a panel looks trivial until you ask what it announces to a screen reader, where focus goes when it closes, and what happens if someone opens it with the keyboard. This guide treats the sidebar menu button as a stateful interaction contract: a set of decisions about name, state, focus and pattern that you make before writing any markup. Get those right and the CSS becomes the easy part.
Table of Contents
- What a Sidebar Menu Button Does and Why It Exists
- Sidebar Button States and the Attributes Behind Them
- Choosing Between Drawer, Overlay and Rail Patterns
- How to Build the Open and Close Behaviour
- Keyboard and Focus Rules Users Depend On
- Common Mistakes and How to Fix Them
- Run These Checks Before You Ship Your Sidebar Button
What a Sidebar Menu Button Does and Why It Exists
Think of a chest of drawers. The sidebar is the drawer holding your site’s navigation. The button is the cabinet handle: a small, always-visible thing that tells you the drawer exists and lets you pull it out. Without the handle, the drawer might as well not be there. Without the drawer, the handle is decoration.
In web terms, a sidebar menu button is a persistent trigger that opens a panel containing navigation that won’t fit in a narrow viewport. The sidebar is the panel itself, usually sliding in from the left or right edge. The button toggles it. The pairing exists because a full desktop navigation bar cannot reliably fit on a phone screen, so secondary navigation gets collapsed behind one control that stays put.
That’s not a stylistic preference. It came out of responsive design as a practical necessity. When GOV.UK launched in October 2012, it replaced separate desktop and mobile versions of Directgov with a single responsive layout that adapted navigation to different screen sizes. At the time, mobile accounted for roughly a fifth of usage; by July 2020, consistently more than half of users accessed the service on mobile, according to GOV.UK’s account of its mobile experience work. The button didn’t appear because someone liked hamburger icons. It appeared because the navigation had to survive on a screen a quarter of the width.

The two-part test that separates a good button from a decorative one:
- A visitor who never opens the panel can still reach every key page. Footer links, in-page links, search, breadcrumbs. The sidebar is an accelerator, not the only road.
- The button itself is never decoration. It carries a name, a state, and a keyboard contract. If you stripped the CSS away, it would still work.
It’s common to get the first part roughly right and underinvest in the second. If you’re still deciding where navigation should live before you decide how it opens, a practical navigation guide for Australian small businesses covers how structure and sales paths interact. Once the structure is settled, the mechanics of the nav bar itself are the next thing to pin down.
Sidebar Button States and the Attributes Behind Them
A sidebar menu button has exactly three states a user can be in at any moment: closed, open, and focused. Each one needs to be visible on screen and announced in markup. The two must agree, because they’re read by different people through different channels and any mismatch is a bug.
| State | Visual cue | aria-expanded | Accessible name | Screen reader announcement |
|---|---|---|---|---|
| Closed | Three stacked lines | false | Open navigation | Open navigation, button, collapsed |
| Open | Cross icon | true | Close navigation | Close navigation, button, expanded |
| Focused (either state) | Visible focus ring | Unchanged | Unchanged | Announces the current state on focus |
Three attributes carry the contract. The element itself must be a native <button>, not a styled <div>, so browsers and assistive technology treat it as an interactive control by default. aria-expanded flips between true and false and must mirror what’s visible on screen. aria-controls points at the panel’s id, which ties the trigger to what it opens.
The rule that saves you a rewrite: if a state exists visually, it exists in the accessibility tree. No exceptions.
The naming decision happens once. You have two valid strategies and a third that’s always wrong:
| Strategy | Accessible name | When to use it |
|---|---|---|
| Changing name | Open navigation / Close navigation | A standalone trigger with no visible label nearby |
| Stable name | Navigation, with aria-expanded carrying state | A button that appears in multiple places or sits beside a visible title |
| Icon as name | None (announced as the file name or glyph) | Never |
Pick one, write it down, apply it everywhere. The icon carries no label of its own. A hamburger drawn in CSS or shipped as an SVG contributes nothing to the accessible name unless you deliberately expose it, and the button’s name is what assistive technology reads.
The closed panel must leave the tab order. Give the hidden panel the hidden attribute, or inert where you need to preserve layout, so keyboard users never land on links they can’t see. A common failure is hiding the panel with opacity: 0 or a transform, which leaves every link focusable and traps users in invisible content.
A short checklist for the markup: name, expanded value, control link, removal from tab order when closed. Get those four right and the rest is styling.
Choosing Between Drawer, Overlay and Rail Patterns
Four patterns cover almost every case, and they fail in different ways. The choice decides your focus rules before you write a line of code, so make it first.
| Pattern | Best for | Mobile behaviour | Focus handling | Main risk |
|---|---|---|---|---|
| Push-down disclosure | Short menus with few levels | Content moves down the page | Focus moves to the first link, no trap | Long lists push content far down |
| Off-canvas drawer | Many items on phone screens | Slides over the page from one edge | Focus trapped until the drawer closes | Blocks the page and hides context |
| Full-screen overlay | Deep, searchable menus | Covers the whole viewport | Focus trapped, Escape closes | Users lose their place on the page |
| Persistent rail | Apps where users switch sections often | Stays visible and collapses to icons | Normal tab order | Uses horizontal space on small screens |

The criteria that decide it are narrow. Count your navigation levels. Count your top-level items. Ask how often a reader switches sections mid-task. Ask whether the page must stay visible while the menu is open. Ask whether the panel blocks interaction with everything behind it. Screen width barely matters. A marketing site with six top-level pages and nothing nested wants push-down disclosure, because the panel is short, the page stays visible, and no focus trap is needed. A SaaS product with a dozen sections wants a drawer on mobile and a persistent rail on desktop, because users jump between sections constantly and the context of the current page matters. A deep catalogue with search wants a full-screen overlay, because the menu is really a search surface with links attached.
Pattern and focus rule must match. A drawer that blocks the page needs a focus trap. A push-down menu must never have one, because trapping focus inside a list of links while the page stays visible is confusing and unnecessary.
Many builds fall apart here. A team copies a drawer component, then turns off the overlay so the page shows through, and keeps the focus trap. Keyboard users now can’t reach the content they can see. The reverse also happens: a full-screen overlay without a trap lets Tab escape behind the panel into invisible content.
Write the rule down next to the pattern choice. If the panel blocks the page, trap focus and return it on close. If the panel sits inline and the page stays usable, leave focus free and let Tab continue in DOM order.
When the viewport widens, the pattern usually has to change, and that transition needs designing too. A drawer that becomes a rail should hand focus back cleanly and drop the trap, because the rail is now part of the page rather than a modal surface. For teams working through the slide-out variant in detail, this drawer component breakdown covers the mechanics. A wider set of conventions sits in this set of menu design advice from Up North Media, useful when you’re briefing a designer on the same decision.
How to Build the Open and Close Behaviour
The build follows the contract. Each step below includes the reason, because a step without a reason gets skipped during a refactor.

-
Render a native
<button>with the name Open navigation. Use the element, not a div with a click handler. The browser gives you keyboard activation, focus behaviour and a proper role for free. The name goes in the button’s text content, visually hidden if needed, not in atitleattribute. -
Add
aria-controlspointing at the panel’s id, and setaria-expanded="false". The panel gets a stable id. The expanded state starts closed because the panel starts hidden. These two attributes are the contract’s public interface. -
Open on click, Enter or Space. Set
aria-expanded="true", reveal the panel, and swap the name to Close navigation if you chose the changing-name strategy. Enter and Space are handled by the native button, which is exactly why step 1 matters. -
Move focus to the first link or the close control inside the panel. A keyboard user who presses Enter needs to know the panel opened and where they now are. Leaving focus on the trigger means the next Tab press may skip the entire menu.
-
Close on a second press, on Escape, or on a click outside. Set
aria-expanded="false", hide the panel, and restore the name if you’re using a changing name. -
Return focus to the triggering button on close. This is the step most implementations miss. Without it, focus lands on the document body and the user has to tab from the top of the page to get back.
-
Remove the hidden panel from the tab order and shorten the transition. Use
hiddenorinertwhen closed. Keep the slide under about 200ms, and switch the animation off entirely inside aprefers-reduced-motion: reducemedia query. An animation that ignores that preference is a real barrier, not a nice-to-have. -
Branch on the pattern. If the panel is a modal drawer, trap focus inside until it closes, and make sure Escape is available from anywhere within. If it’s a disclosure, leave focus free. This branch is the one thing you can’t decide during implementation.
Here’s a working reference for the interaction, if you want to see the sequence in motion before you build it.
Correct interaction feels unremarkable. One press opens it. One press or Escape closes it. The page doesn’t scroll behind an open drawer unless the design says it should. Focus lands somewhere sensible and comes back where it started. Nothing announces twice, nothing announces nothing.
Test the branch before the animation. If the trap is wrong, no amount of easing will make the drawer feel right to a keyboard user.
Keyboard and Focus Rules Users Depend On
Keyboard support belongs to the interaction contract you settle before any markup exists: the button has a name, it announces its expanded state, and every key press has a defined outcome. For some users, the keyboard is the only way the navigation exists at all.
| Key | What it does | Expected result |
|---|---|---|
| Enter or Space | Activates the button | Panel opens and focus moves to the first link or close control |
| Tab and Shift+Tab | Moves through links inside the open panel | Focus follows the visual order and stays inside the panel when it is a modal |
| Escape | Closes the open panel | Panel closes and focus returns to the sidebar button |
| Skip link | Jumps past repeated navigation | Focus lands on the main content area |
The stakes are concrete. The Click-Away Pound 2019 report estimated that 7.15 million disabled internet users in the UK had access needs, and 71% said their disability affected how they used the internet. Participants in that research commonly hit barriers on websites they visited, and a large share said they would stay longer on sites that worked for them.
For a menu button, that translates directly into lost access. If the button lacks an accessible name, keyboard operation, focus management or an announced open and closed state, users may be unable to reach the pages they came for, even when the content sits ready on the server. The button becomes the lock on the whole site.
The pattern repeats across the public sector. UK accessibility monitoring found 26,171 accessibility issues across websites and apps assessed from 2022 to 2024, with 3.7% concerning keyboard access and 7.1% concerning visible focus, according to the 2022 to 2024 monitoring report. The report names a failure mode that sidebar builders will recognise: dropdown navigation that keyboards can’t expand, or focus that wanders through links inside a visually collapsed menu. That second case confuses readers because the page looks fine. The tab key walks through items nobody can see.
The test that catches almost everything. Unplug the mouse. From the top of the page, Tab to the button, press Enter, tab through the open panel, press Escape, and confirm focus lands back on the button. If any step surprises you, a real user will hit it too.
Two details are easy to forget. Focus must remain visible at every stop, so never strip the outline without a replacement; a solid 2px ring that passes contrast works. And the skip link must come first in the tab order, ahead of the menu button, so keyboard users can bypass repeated navigation on every page. Think of the skip link as the fire exit of the tab order: rarely used by sighted mouse users, always needed by the people it serves. If you’ve had trouble keeping the ring consistent across components, this guide to focus-visible styling covers the selector behaviour.
Common Mistakes and How to Fix Them
The build steps above eliminate the structural errors. These are the ones that survive into production because they live in styling and interaction details.
-
A
<div>with a click handler instead of a<button>. Enter and Space do nothing, and keyboard users skip past it entirely. Swap in a real button element and delete the handler’s role andtabindexpatches. -
Hover-only opening. On a touchscreen there’s no hover state, so the panel never appears. Open on click or tap, and treat hover as an optional desktop enhancement only.
-
A touch target under about 44 by 44 pixels. A 24px icon in a 24px box is a miss waiting to happen. Expand the hit area with padding, keeping the visual icon the same size.
-
A slide animation that ignores reduced-motion. Some users get motion sickness from sliding panels. Wrap the transform in a
prefers-reduced-motionquery and switch to an instant show or a short fade. -
An icon styled as bare text. Light grey glyphs on white pass no contrast check, and the focus ring vanishes when the icon has no background box. Give the icon enough contrast and keep a visible ring on the button itself.
-
An open drawer that lets the page scroll behind it. On mobile, the user drags the panel and scrolls the article underneath, then closes the drawer somewhere unexpected. Lock body scroll while a modal drawer is open, and release it on close.
-
A state that never announces. If
aria-expandedsits on the SVG or a wrapper span rather than the button, screen readers report nothing. Move the attribute onto the element that receives focus.
Each one is a five-minute fix during development and a support ticket after launch.
Run These Checks Before You Ship Your Sidebar Button
Run this list against the built page, not the design file. Every item is testable in a browser with a keyboard and a screen reader.

- The trigger is a native button and uses one naming strategy throughout the site.
aria-expandedandaria-controlsare correct and update on every open and close.- Enter, Space and Escape all work from the keyboard alone.
- Focus moves into the panel and returns to the trigger when it closes.
- The hidden panel leaves the tab order with
hiddenorinert. - The skip link works as the first focusable element on the page.
- The animation respects reduced-motion and stays short.
- A screen reader announces the state, not just the name.
- The touch target is at least about 44 by 44 pixels.
- The panel behaves when the viewport widens, especially where a drawer becomes a rail.
Test in three passes. First, keyboard only, with the mouse unplugged. Second, a screen reader pass with VoiceOver, NVDA or TalkBack, listening specifically for the name and the expanded state. Third, a phone at a narrow viewport, opening and closing the panel repeatedly while the page is scrolled. If you need nested navigation inside the panel, our DomMenuStack component stacks submenus that slide within their container on mobile and desktop, with hover, ArrowRight, Enter and Space opening a submenu and ArrowLeft or Escape returning to the parent, so the focus work is handled for you.
The wider bar is still low. Warbox’s 2025 review of more than 1,200 UK websites across 14 sectors found that 48% still needed accessibility improvements, based on PageSpeed Insights accessibility scores. A sidebar button that passes the list above puts you in the better half.
Choose the pattern that fits the task, write the contract down before the markup, and test with keys alone before release.
If you’d rather not rebuild the focus trap, state announcements and Escape handling on every project, DOM Studio’s navigation primitives ship that behaviour as standard, including a collapsible sidebar shell with a mobile drawer and a menu stack that respects reduced-motion preferences. Browse the DOM Studio component library to see the sidebar, drawer and menu patterns wired up, then spend your testing time on the parts only your product can get right.
