Responsive Navbar
Single-file tailwind responsive navbar with logo, links, CTA, and mobile hamburger.
<nav class="w-full bg-white border-b border-slate-200">
<div class="max-w-7xl mx-auto px-4 h-16 flex items-center justify-between">
<a href="#" class="text-lg font-black text-slate-900">Brand</a>
<div class="hidden md:flex items-center gap-8 text-sm font-semibold text-slate-600">
<a href="#" class="text-slate-900">Home</a>
<a href="#" class="hover:text-slate-900 transition-colors">Features</a>
<a href="#" class="hover:text-slate-900 transition-colors">Pricing</a>
<a href="#" class="hover:text-slate-900 transition-colors">Blog</a>
</div>
<div class="flex items-center gap-3">
<a href="#" class="hidden md:inline-block text-sm font-bold bg-slate-900 text-white px-4 py-2 rounded-lg hover:bg-slate-700 transition-colors">Get started</a>
<button type="button" aria-label="Open menu" class="md:hidden p-2 rounded-lg text-slate-600 hover:bg-slate-200">
<svg class="w-6 h-6" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" d="M4 7h16M4 12h16M4 17h16"/></svg>
</button>
</div>
</div>
</nav>Free to use in personal and commercial projects. No attribution required.
About this responsive navbar
A tailwind responsive navbar is the header nearly every site needs: logo on the left, links in the middle, a call to action on the right, collapsing into a hamburger on phones. Developers searching for a responsive navigation bar html snippet want one file with no framework, something they can paste into a project and wire up in minutes.
This tailwind navbar menu uses a max-w-7xl container with an h-16 flex row. The link list hides below the md breakpoint while the hamburger appears, which is the standard responsive swap. The CTA stays visible on desktop and tucks into the mobile menu, keeping the header to a single row on small screens where space is precious.
Keep the link count low: five or fewer top-level items, with the rest in a dropdown or footer. Make the header sticky with sticky top-0 z-40 and a backdrop blur if navigation matters while scrolling. The hamburger needs a real menu panel behind it, so pair this snippet with a small script that toggles a mobile link list under the bar.
Most visitors do not arrive at your homepage; they land deep-linked from search onto one specific page. Without a navbar they are stranded there, with no map of the rest of the site and no obvious way home. The header is the constant orientation device: logo, sections, and the path back, present on every screen. Sites without one leak visitors who would otherwise have explored.
The responsive swap uses two menus and one breakpoint: the desktop link row shows with hidden md:flex while the hamburger appears with md:hidden. A small script toggles a vertical mobile panel under the bar. Both menus carry identical links, so nothing is lost on small screens and search engines see one consistent navigation. The bar itself is a max-w-7xl container with an h-16 flex row: logo left, links center, CTA right.
Collapse into a hamburger below the lg breakpoint, but keep the CTA visible outside the menu; burying the call to action kills mobile conversion. Shrink the bar from h-16 to h-12 after scrolling 100px on content pages; the reclaimed space matters on small screens. Highlight the current section in the nav so visitors always know where they are; a navbar with no active state is a map with no you-are-here dot. Debounce the scroll listener with requestAnimationFrame; scroll handlers are the classic jank source.
The mobile menu that does not lock body scroll is a quiet disaster. Visitors open the menu, swipe to read it, and the page behind scrolls instead, leaving the menu stranded halfway off screen. Add overflow-hidden to the body while the menu is open and remove it on close. It is three lines of code and the difference between a menu that works and one that fights the user.
Design notes
When to use
A responsive navbar is the header nearly every site needs: logo on the left, links in the middle, a call to action on the right, collapsing into a hamburger on phones. It gives visitors constant orientation and a way home from anywhere. It works hardest on content sites where people arrive deep-linked and need to discover the rest.
What to avoid
Do not cram more than about seven top-level links in, because a crowded navbar helps nobody find anything. Avoid showing a hamburger on desktop when there is room for the real links, since hiding navigation behind a tap costs engagement. And do not make the call to action visually identical to plain links, or it stops being a call to action.
Accessibility
Wrap the navigation in a nav landmark, make the hamburger a real button with aria-expanded, and ensure the mobile menu is fully keyboard navigable with visible focus. Add a skip link so keyboard users can jump past the navbar to the content.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Dark
For dark sites and dashboards where a white bar would glare.
Floating pill
Detached rounded bar that floats over hero sections on modern landing pages.
Minimal
Logo plus CTA only, for focused landing pages with no navigation to distract.
Where to use it
- ✓ Marketing site headers
- ✓ SaaS application top bars
- ✓ Blog navigation
- ✓ Portfolio sites
Frequently asked questions
How do I build a tailwind responsive navbar with a hamburger menu?
Hide the desktop link row below the md breakpoint with hidden md:flex, show a hamburger button with md:hidden, and toggle a vertical mobile menu panel with a click handler. Keep both menus' links identical so nothing is lost on small screens.
Should the navbar be sticky?
For most marketing and app sites, yes: sticky top-0 keeps navigation one tap away and lifts conversion on long pages. Add a subtle border or shadow on scroll so the bar reads as separate from content.
How many links belong in a navbar?
Five or fewer top-level links. More than that overwhelms scanners and crowds mobile menus. Push secondary pages into the footer or a 'More' dropdown, and give the single most important action the CTA button treatment.
How do I animate a hamburger icon into an X when the menu opens?
Build the icon from two or three span bars with transition-transform applied. When the menu opens, rotate the top bar 45 degrees, rotate the bottom bar minus 45 degrees, and fade out the middle bar. Toggle these classes with the same JavaScript that opens the menu so the icon and panel never get out of sync.
How do I make a mobile menu accessible?
Give the toggle button aria-expanded and aria-controls pointing to the menu element, updating aria-expanded on every toggle. Keep menu links out of the tab order while closed by hiding the menu with the hidden attribute. Support the Escape key to close the menu and return focus to the toggle button.
Should a sticky navbar shrink when the user scrolls?
Shrinking padding on scroll adds polish for content-heavy sites, but keep the logo and primary CTA always visible. Use a throttled or rAF-based scroll listener to toggle a compact class past about 40 pixels. Avoid animating height directly, since it triggers layout work on every scroll frame.
Customization tips
Go dark with bg-slate-900 and light text, or add bg-white/80 backdrop-blur for a glassy sticky header. Swap the text logo for an SVG mark. Underline the active link with a border-b-2 or an ::after indicator so users know where they are.