Skip to content

Navbar with Dropdown and Mobile Menu

Tailwind CSS navbar with an accessible dropdown, call-to-action buttons and a collapsible mobile menu.

Also known as: navbar with submenu, header with dropdown menu, responsive navigation bar, mobile hamburger menu

Navbar with Dropdown and Mobile Menu live demo

Open in new tab

Tailwind CSS code (HTML, JS)

A Tailwind CSS header with a logo, a keyboard-friendly "Solutions" dropdown, login and sign-up actions and a separate mobile menu. It suits SaaS marketing sites, product pages and company websites that need a clean top navigation with a submenu.

How it works

The root is header.tnd-nav. Inside the nav, the desktop links and the auth buttons use hidden md:flex, so they appear only from the md breakpoint. The dropdown is a relative wrapper with data-dropdown, containing a button with data-dropdown-button and an absolutely positioned panel #tnd-solutions with data-dropdown-menu, which starts with the hidden class. Each menu item shows a title and a short description. Below md, a hamburger button with data-mobile-button (visible via md:hidden) controls the #tnd-mobile panel marked data-mobile-menu.

The script runs on DOMContentLoaded for every .tnd-nav. For each data-dropdown it toggles the hidden class on the menu, sets aria-expanded on the button and rotates the chevron with rotate-180. ArrowDown on the button opens the menu and focuses the first link; ArrowDown and ArrowUp inside the menu cycle through links; Escape closes it and returns focus to the button; a click anywhere outside the dropdown closes it. The mobile button toggles hidden on the mobile panel, updates aria-expanded and changes its sr-only text between "Open main menu" and "Close main menu".

Customization

  • emerald classes (text-emerald-600 on the logo, bg-emerald-600 on Sign up, focus-visible:ring-emerald-500): replace with another Tailwind color such as indigo to rebrand.
  • md:flex and md:hidden: change to lg:flex and lg:hidden on all four elements to keep the mobile menu up to a wider screen.
  • w-64 on #tnd-solutions: widen the dropdown panel for longer descriptions.
  • left-0 on #tnd-solutions: use right-0 to align the panel to the right edge of its button.
  • Add more a elements inside the data-dropdown-menu panel; the arrow-key navigation picks them up automatically.
  • Copy the whole data-dropdown wrapper to add a second dropdown, with a new menu id and matching aria-controls.
  • max-w-6xl on the nav: change the width of the content area.

Use cases

  • SaaS marketing sites: a Solutions dropdown lists each offering with a short description
  • Product pages: login and sign-up buttons stay visible in the header on desktop
  • Company websites: a clean top navigation switches to a hamburger menu on phones
  • Keyboard-friendly sites: arrow keys and Escape work inside the submenu

Accessibility

The nav has aria-label="Main", and the current page link uses aria-current="page". The dropdown button exposes aria-expanded, aria-haspopup and aria-controls, and supports arrow keys, Escape with focus return, and outside clicks. The mobile toggle has aria-controls="tnd-mobile", a synced aria-expanded state and a changing sr-only label. Buttons show focus-visible rings, menu links get a background on focus, and all SVG icons are aria-hidden.

Usage notes

Needs the Tailwind browser build (added automatically); there is no style.css. The mobile panel lists Solutions as a plain link, so point it to an overview page or expand it into sub-links.

Navbar with Dropdown and Mobile Menu at a glance

Framework
Tailwind CSS
Code
HTML, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Navbars
License
Free for personal and commercial use

Questions about this template

Can I use the Navbar with Dropdown and Mobile Menu code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Navbar with Dropdown and Mobile Menu – free Tailwind CSS navbar template
Navbar with Dropdown and Mobile Menu · free Tailwind CSS navbar template

More Navbars

Navbar with Sliding Active Indicator – free Pure CSS navbar template

Navbar with Sliding Active Indicator

Dark responsive navbar with a glowing underline that slides between links on hover, focus and click, built with CSS custom properties and vanilla JS.

Navbar with Offcanvas Drawer on Mobile – free Bootstrap 6 navbar template

Navbar with Offcanvas Drawer on Mobile

Responsive Bootstrap 6 navbar that shows inline links on desktop and moves them into a slide-in Drawer with icons, studio hours and social links on small screens.

Navbar with Overflow Menu (NavOverflow) – free Bootstrap 6 navbar template

Navbar with Overflow Menu (NavOverflow)

Bootstrap 6 news navbar built on the new NavOverflow component: links that do not fit move into a More menu automatically as the width shrinks.

Navbar with Centered Logo – free Tailwind CSS navbar template

Navbar with Centered Logo

Dark Tailwind CSS navbar with links split around a centered logo, animated underlines and an accessible slide-down mobile menu.