Developer and Text Tools

How to Build an Accessible Responsive Navbar With Dropdowns

What a good site header needs on phones and desktops, how the accessible disclosure pattern works, and how to generate the HTML, CSS and script.

Saizul Amin
Saizul Amin5 Nov 2026 · 3 min read
How to Build an Accessible Responsive Navbar With Dropdowns

The navigation bar is the most used component on most websites, and one of the most often broken. Common faults include dropdowns that only open on hover and therefore never on a phone, menu buttons that screen readers announce as an unlabelled button, menus that cannot be closed with the keyboard, and layouts that jump when the screen crosses a breakpoint. None of this is hard to get right, but it takes more care than a quick copy from a code snippet site.

What a good navbar does

On a wide screen, links sit in a row next to the brand, and items with sub-pages open a dropdown on click, on Enter, and optionally on hover. On a narrow screen the links fold into a menu button. The menu opens as a panel below the bar or as a drawer from the side, every target is at least 44 pixels high, and the current page is visibly marked.

For keyboard and screen reader users, the button that opens a menu says whether it is open with aria-expanded, points to the menu with aria-controls, and has a label such as Open menu. Pressing Escape closes the innermost open menu and returns focus to its button. Clicking outside closes everything. This is the disclosure navigation pattern from the W3C's ARIA Authoring Practices. It is simpler and more robust than the full ARIA menu role, which is meant for application menus rather than site navigation.

Why dropdown parents become buttons

A top-level item cannot both go to a page and open a list on a touch screen, because a tap can only do one of the two. The accessible solution is to make the parent a button that opens the dropdown, and put the parent page inside the list as its first link if it needs to be reachable.

Building it step by step

Open the Responsive Navbar Generator. The live preview at the top runs the real code, so every change is visible at once.

  1. Brand and button. Type the site name or paste a logo address, and set the text and link of the call-to-action button, or leave the text empty for no button.
  2. Menu items. Rename items, change links, move them up and down and delete them. Open Dropdown on any item to add links under it. Mark the item for the current page so it gets aria-current and the accent colour.
  3. Layout. Choose where the links sit, the bar height and maximum content width, sticky positioning, shadow and border, and the breakpoint where the mobile menu takes over. Pick a panel or a side drawer for phones.
  4. Colours. Start from the Light, Dark, Brand or Minimal theme and adjust. The contrast figures for links and the button tell you whether the text is readable, with 4.5:1 as the target.
  5. Test. Switch the preview between full, tablet and phone widths. Open the menu, expand a dropdown, then press Tab, Enter and Escape to check the keyboard behaviour.
  6. Export. Copy the HTML, CSS and script separately or download a single HTML file. Save the settings as a JSON file to continue later.

Fitting it into your site

Paste the HTML at the start of the body, the CSS into your stylesheet and the script before the closing body tag. All class names share one prefix, nb by default, which you can change to avoid clashes. In a real site the current page changes from page to page, so set aria-current in your template rather than in the generated code.

Where the generator stops

It builds one bar with one level of dropdowns. Mega menus with columns, search boxes inside the bar and nested sub-menus are deliberately left out, because they need design decisions that a generator cannot make well. For most sites, a clear bar with a handful of links and one or two dropdowns works better anyway.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages