Naye tools shamil kiye gaye! Dekhein kya naya hai

Home/Components/Responsive Navbar

Responsive Navbar examples

Aik mobile-first navigation bar jis mein logo, links, aik call-to-action, aur hamburger menu hota hai jo medium breakpoint ke baad collapse ho jata hai.

Aik navigation bar jo desktop par horizontal link row dikhata hai aur md breakpoint se neeche aik hamburger menu mein collapse ho jata hai. Is mein logo slot, primary call-to-action, keyboard support, aur woh ARIA attributes shamil hain jo screen readers ko menu theek se announce karne ke liye chahiye hote hain.

Kisi bhi project ke liye HTML version copy karein, ya Next.js, Vite, ya Create React App ke liye React version lein. Tailwind CSS ke ilawa koi aur dependencies nahi hain.

Classic responsive navbar

A flat white bar with a hairline border, a link row, and a square-cornered call-to-action. Collapses to a hamburger with aria-expanded wiring and Escape to close. The safe default for most sites.

Preview
"use client";

import { useEffect, useState } from "react";

const links = ["Icons", "Tools", "Components"];

export default function Navbar() {
  const [open, setOpen] = useState(false);

  useEffect(() => {
    if (!open) return;
    const onKey = (e: KeyboardEvent) => {
      if (e.key === "Escape") setOpen(false);
    };
    document.addEventListener("keydown", onKey);
    return () => document.removeEventListener("keydown", onKey);
  }, [open]);

  return (
    <header className="border-b border-gray-200 bg-white">
      <nav className="mx-auto flex max-w-7xl items-center justify-between px-4 py-4">
        <a href="#">
          <img src="https://www.utilityzoo.com/logo.svg" alt="Utility Zoo" className="h-6 w-auto" />
        </a>

        <ul className="hidden items-center gap-8 md:flex">
          {links.map((label) => (
            <li key={label}>
              <a href="#" className="text-sm font-medium text-gray-600 hover:text-gray-900">{label}</a>
            </li>
          ))}
        </ul>

        <a href="#" className="hidden rounded-md bg-gray-900 px-4 py-2 text-sm font-medium text-white hover:bg-gray-700 md:inline-block">
          Get started
        </a>

        <button
          type="button"
          onClick={() => setOpen(!open)}
          aria-expanded={open}
          aria-controls="mobile-menu"
          aria-label={open ? "Close main menu" : "Open main menu"}
          className="rounded-md p-2 text-gray-600 hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 md:hidden"
        >
          <svg className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth={1.5} viewBox="0 0 24 24" aria-hidden="true">
            <path strokeLinecap="round" strokeLinejoin="round" d={open ? "M6 18 18 6M6 6l12 12" : "M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5"} />
          </svg>
        </button>
      </nav>

      {open && (
        <div id="mobile-menu" className="border-t border-gray-200 md:hidden">
          <ul className="space-y-1 px-4 py-4">
            {links.map((label) => (
              <li key={label}>
                <a href="#" className="block rounded-md px-3 py-2 text-base font-medium text-gray-700 hover:bg-gray-100">{label}</a>
              </li>
            ))}
            <li className="pt-2">
              <a href="#" className="block rounded-md bg-gray-900 px-3 py-2 text-center text-base font-medium text-white">
                Get started
              </a>
            </li>
          </ul>
        </div>
      )}
    </header>
  );
}

Sticky navbar with glass blur

Stays pinned to the top while content scrolls beneath a translucent, blurred bar. Pill-shaped hover states on the links. The mobile menu uses a native details element, so there is no JavaScript.

Preview
export default function StickyNavbar() {
  return (
    <header className="sticky top-0 z-50 border-b border-gray-200/60 bg-white/70 backdrop-blur-md">
      <nav className="relative mx-auto flex max-w-7xl items-center justify-between px-4 py-3">
        <a href="#"><img src="https://www.utilityzoo.com/logo.svg" alt="Utility Zoo" className="h-6 w-auto" /></a>

        <ul className="hidden items-center gap-1 md:flex">
          <li><a href="#" className="rounded-full px-3 py-1.5 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900">Icons</a></li>
          <li><a href="#" className="rounded-full px-3 py-1.5 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900">Tools</a></li>
          <li><a href="#" className="rounded-full px-3 py-1.5 text-sm text-gray-600 hover:bg-gray-100 hover:text-gray-900">Components</a></li>
        </ul>

        <a href="#" className="hidden rounded-full bg-gray-900 px-4 py-1.5 text-sm font-medium text-white hover:bg-gray-700 md:inline-block">Sign in</a>

        <details className="md:hidden">
          <summary aria-label="Toggle main menu" className="flex cursor-pointer list-none rounded-md p-2 text-gray-600 hover:bg-gray-100 [&::-webkit-details-marker]:hidden">
            <svg className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5" /></svg>
          </summary>
          <div className="absolute inset-x-0 top-full border-b border-gray-200 bg-white/95 px-4 py-3 shadow-sm backdrop-blur-md">
            <ul className="space-y-1">
              <li><a href="#" className="block rounded-xl px-3 py-2.5 text-base text-gray-700 hover:bg-gray-100">Icons</a></li>
              <li><a href="#" className="block rounded-xl px-3 py-2.5 text-base text-gray-700 hover:bg-gray-100">Tools</a></li>
              <li><a href="#" className="block rounded-xl px-3 py-2.5 text-base text-gray-700 hover:bg-gray-100">Components</a></li>
              <li className="pt-2"><a href="#" className="block rounded-full bg-gray-900 px-3 py-2.5 text-center text-base font-medium text-white">Sign in</a></li>
            </ul>
          </div>
        </details>
      </nav>
    </header>
  );
}

Floating rounded navbar

A detached, fully rounded bar that floats above the page with a soft colored shadow. Pairs well with a hero that has a gradient or image background.

Preview
export default function FloatingNavbar() {
  return (
    <header className="px-4 pt-4">
      <nav className="relative mx-auto flex max-w-4xl items-center justify-between rounded-full border border-white/70 bg-white/85 px-5 py-2.5 shadow-lg shadow-sky-200/60 backdrop-blur">
        <a href="#"><img src="https://www.utilityzoo.com/logo.svg" alt="Utility Zoo" className="h-6 w-auto" /></a>

        <ul className="hidden items-center gap-7 md:flex">
          <li><a href="#" className="text-sm font-medium text-gray-600 hover:text-gray-900">Icons</a></li>
          <li><a href="#" className="text-sm font-medium text-gray-600 hover:text-gray-900">Tools</a></li>
          <li><a href="#" className="text-sm font-medium text-gray-600 hover:text-gray-900">Components</a></li>
        </ul>

        <a href="#" className="hidden rounded-full bg-[#168f9a] px-4 py-1.5 text-sm font-medium text-white hover:bg-[#127782] md:inline-block">Get started</a>

        <details className="md:hidden">
          <summary aria-label="Toggle main menu" className="flex cursor-pointer list-none rounded-full p-2 text-gray-700 hover:bg-gray-100 [&::-webkit-details-marker]:hidden">
            <svg className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5" /></svg>
          </summary>
          <div className="absolute inset-x-0 top-full mt-3 rounded-3xl bg-white p-3 shadow-xl ring-1 ring-black/5">
            <ul className="space-y-1">
              <li><a href="#" className="block rounded-2xl px-4 py-2.5 text-base font-medium text-gray-700 hover:bg-gray-100">Icons</a></li>
              <li><a href="#" className="block rounded-2xl px-4 py-2.5 text-base font-medium text-gray-700 hover:bg-gray-100">Tools</a></li>
              <li><a href="#" className="block rounded-2xl px-4 py-2.5 text-base font-medium text-gray-700 hover:bg-gray-100">Components</a></li>
              <li className="pt-1"><a href="#" className="block rounded-full bg-[#168f9a] px-4 py-2.5 text-center text-base font-medium text-white">Get started</a></li>
            </ul>
          </div>
        </details>
      </nav>
    </header>
  );
}

Dark navbar with dropdown menu

A near-black bar with an inverted logo and a Tools dropdown that opens on hover and on keyboard focus. On mobile the dropdown items flatten into the main list.

Preview
export default function DarkNavbar() {
  return (
    <header className="border-b border-white/10 bg-gray-950">
      <nav className="relative mx-auto flex max-w-7xl items-center justify-between px-4 py-4">
        <a href="#"><img src="https://www.utilityzoo.com/logo.svg" alt="Utility Zoo" className="h-6 w-auto brightness-0 invert" /></a>

        <ul className="hidden items-center gap-8 md:flex">
          <li className="group relative">
            <button type="button" className="flex items-center gap-1 text-sm text-gray-300 hover:text-white focus:outline-none focus-visible:text-white">
              Tools
              <svg className="h-4 w-4" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="m19.5 8.25-7.5 7.5-7.5-7.5" /></svg>
            </button>
            <div className="invisible absolute left-0 top-full z-10 w-56 pt-3 opacity-0 transition group-focus-within:visible group-focus-within:opacity-100 group-hover:visible group-hover:opacity-100">
              <ul className="rounded-lg bg-white p-2 shadow-lg ring-1 ring-black/5">
                <li><a href="#" className="block rounded-md px-3 py-2 text-sm text-gray-700 hover:bg-gray-100">Code tools</a></li>
                <li><a href="#" className="block rounded-md px-3 py-2 text-sm text-gray-700 hover:bg-gray-100">Audio tools</a></li>
                <li><a href="#" className="block rounded-md px-3 py-2 text-sm text-gray-700 hover:bg-gray-100">PDF tools</a></li>
              </ul>
            </div>
          </li>
          <li><a href="#" className="text-sm text-gray-300 hover:text-white">Icons</a></li>
          <li><a href="#" className="text-sm text-gray-300 hover:text-white">Components</a></li>
        </ul>

        <a href="#" className="hidden rounded-md bg-white px-4 py-2 text-sm font-medium text-gray-900 hover:bg-gray-200 md:inline-block">Get started</a>

        <details className="md:hidden">
          <summary aria-label="Toggle main menu" className="flex cursor-pointer list-none rounded-md p-2 text-gray-300 hover:bg-gray-800 [&::-webkit-details-marker]:hidden">
            <svg className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5" /></svg>
          </summary>
          <div className="absolute inset-x-0 top-full border-t border-white/10 bg-gray-950 px-4 py-3">
            <ul className="space-y-1">
              <li><a href="#" className="block rounded-md px-3 py-2 text-base text-gray-200 hover:bg-gray-800">Code tools</a></li>
              <li><a href="#" className="block rounded-md px-3 py-2 text-base text-gray-200 hover:bg-gray-800">Audio tools</a></li>
              <li><a href="#" className="block rounded-md px-3 py-2 text-base text-gray-200 hover:bg-gray-800">PDF tools</a></li>
              <li><a href="#" className="block rounded-md px-3 py-2 text-base text-gray-200 hover:bg-gray-800">Icons</a></li>
              <li><a href="#" className="block rounded-md px-3 py-2 text-base text-gray-200 hover:bg-gray-800">Components</a></li>
              <li className="pt-2"><a href="#" className="block rounded-md bg-white px-3 py-2 text-center text-base font-medium text-gray-900">Get started</a></li>
            </ul>
          </div>
        </details>
      </nav>
    </header>
  );
}

Centered logo navbar with announcement bar

A gradient announcement strip above a three-column bar: links on the left, centered logo, actions on the right. Uppercase tracked links give it an editorial feel.

Preview
export default function CenteredNavbar() {
  return (
    <header className="bg-white">
      <div className="bg-gradient-to-r from-[#168f9a] via-[#2bb4c0] to-[#5ed6c0] px-4 py-2 text-center text-xs font-medium text-white">
        New: 40 more free tools just launched.
        <a href="#" className="underline underline-offset-2">See what is new</a>
      </div>

      <nav className="relative mx-auto grid max-w-7xl grid-cols-3 items-center border-b border-gray-200 px-4 py-4">
        <ul className="hidden items-center gap-6 md:flex">
          <li><a href="#" className="text-xs font-semibold uppercase tracking-wider text-gray-600 hover:text-gray-900">Icons</a></li>
          <li><a href="#" className="text-xs font-semibold uppercase tracking-wider text-gray-600 hover:text-gray-900">Tools</a></li>
          <li><a href="#" className="text-xs font-semibold uppercase tracking-wider text-gray-600 hover:text-gray-900">Components</a></li>
        </ul>

        <details className="md:hidden">
          <summary aria-label="Toggle main menu" className="flex cursor-pointer list-none rounded-md p-2 text-gray-600 hover:bg-gray-100 [&::-webkit-details-marker]:hidden w-fit">
            <svg className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth="1.5" viewBox="0 0 24 24" aria-hidden="true"><path strokeLinecap="round" strokeLinejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5M3.75 17.25h16.5" /></svg>
          </summary>
          <div className="absolute inset-x-0 top-full border-b border-gray-200 bg-white px-4 py-3 shadow-sm">
            <ul className="space-y-1">
              <li><a href="#" className="block rounded-md px-3 py-2 text-sm font-semibold uppercase tracking-wider text-gray-700 hover:bg-gray-100">Icons</a></li>
              <li><a href="#" className="block rounded-md px-3 py-2 text-sm font-semibold uppercase tracking-wider text-gray-700 hover:bg-gray-100">Tools</a></li>
              <li><a href="#" className="block rounded-md px-3 py-2 text-sm font-semibold uppercase tracking-wider text-gray-700 hover:bg-gray-100">Components</a></li>
            </ul>
          </div>
        </details>

        <a href="#" className="justify-self-center"><img src="https://www.utilityzoo.com/logo.svg" alt="Utility Zoo" className="h-7 w-auto" /></a>

        <div className="flex items-center justify-end gap-4">
          <a href="#" className="hidden text-sm text-gray-600 hover:text-gray-900 sm:block">Sign in</a>
          <a href="#" className="rounded-full border border-gray-300 px-4 py-1.5 text-sm font-medium text-gray-900 hover:bg-gray-50">Get started</a>
        </div>
      </nav>
    </header>
  );
}

What is a Responsive Navbar?

Responsive navbar page ke top par woh horizontal bar hoti hai jo site ki identity aur primary navigation ko hold karti hai. Wide screen par yeh links ko aik row mein dikhati hai kyunke wahan un ke liye jagah hoti hai. Narrow screen par woh row ya toh parhne mein mushkil uljhan ban jaye gi ya edge se bahar nikal jaye gi, is liye links aik panel mein chale jaate hain jo aik button - hamburger - se open aur close hota hai. Yeh component asal mein aik hi content ke liye do layouts hain, jahan breakpoint decide karta hai ke kaunsa visible hoga.

Yeh interface work mein sab se zyada use hone wala component hai, aur aksar sab se buri tarah banaya jata hai bhi yeh hi hai. Aik navbar jo sirf do specific widths par theek dikhe, ya jo keyboard users ko open menu ke andar phasa le, ya jo assistive technology se apne links chupaye kyunke panel ko document se remove karne ke bajaye opacity se style kiya gaya ho, yeh sab aise tareeqon se fail hote hain jo banane wale ko nazar nahi aate lekin unhein saaf dikhte hain jo is se mutasir hote hain. Neeche diya gaya markup un specific failures se bachne ke liye likha gaya hai na ke sab se chota version banane ke liye.

Breakpoint ki choice jitni lagti hai us se zyada zaroori hai. md (768px) par collapse hona aam default hai, aur yeh tab kaam karta hai jab aap ke paas chaar ya paanch chhote links hon. Saat links ke sath, ya lambe labels ke sath, row 768px se pehle hi khatam ho jati hai aur layout us gap mein toot jata hai jahan yeh fit hona band hota hai aur jahan yeh collapse hota hai. Kisi real browser mein sab se lambe label ko check karein aur agar row tight ho toh breakpoint ko lg par move kar dein - class prefixes hi sirf woh cheez hain jo change karni parti hain.

Yahan mobile panel jab close hota hai toh document se remove ho jata hai, HTML version mein hidden attribute aur React mein conditional rendering use kar ke, na ke kisi class ke zariye chupaya jata hai. Yeh farq cosmetic nahi hai: opacity-0 ya transform se chupaya gaya panel abhi bhi focusable hota hai aur read aloud hota hai, is liye keyboard aur screen reader users un links par tab kar sakte hain jo unhein nazar nahi aate. Element ko remove karna hi woh behaviour hai jo log expect karte hain.

Anatomy

Header
Outer landmark element. Div ke bajaye real header tag use karne se assistive technology ko banner landmark milta hai jis par woh jump kar sakti hai, aur yeh hi tareeqa hai jis se bohot se screen reader users page ke top par navigate karte hain.
Brand
Logo ya wordmark, jo home page se linked ho. Isay DOM mein sab se pehle rakhein taake jab page par tab kiya jaye toh yeh sab se pehli cheez ho.
Desktop link row
Links ki list, jo breakpoint se neeche hidden md:flex ke sath hidden hoti hai. Yeh aik real ul hai taake screen readers read karne se pehle announce kar sakein ke is mein kitne items hain.
Call-to-action
Woh aik action jo aap chahte hain ke visitor sab se pehle le, links se alag style kiya gaya hai taake yeh koi doosra navigation item na lage.
Toggle button
Hamburger, jo sirf breakpoint se neeche visible hota hai. Is mein aria-expanded, aria-controls, aur aik aria-label hota hai jo state ke sath change hota hai taake button yeh announce kare ke yeh kya karega na ke yeh kaisa dikhta hai.
Mobile panel
Stacked link list jo toggle karne par nazar aati hai. Close hone par document se remove ho kar di jati hai, aur desktop links se baray tap targets diye jaate hain kyunke yeh thumb ke sath use ho raha hota hai.

How to Use

  1. 1

    Markup copy karein

    Apne stack ke hisab se HTML ya React version lein. Next.js App Router mein, React version ke top par use client directive lazmi rakhein - yeh component open state rakhta hai aur server component nahi ho sakta.

  2. 2

    Brand aur links replace karein

    Wordmark ko apne logo se badlein aur links array ko edit karein. HTML version mein desktop row aur mobile panel alag markup hain, is liye dono ko change karein; React version mein woh aik hi array share karte hain.

  3. 3

    Apna breakpoint set karein

    Component by default md par collapse hota hai. Agar aapki link row lambi hai, toh har md: prefix ko lg: mein change kar dein aur yeh pehle collapse ho jaye ga. Us width par test karein jahan aapka sab se lamba label aata hai.

  4. 4

    Surface ko restyle karein

    Header par background, border, aur text classes ko apne design ke mutabiq change karein. Nav container ke andar ki har cheez apna spacing inherit karti hai, is liye color change karne se layout kharab nahi hota.

  5. 5

    Keyboard ke sath check karein

    Bar par Tab press karein, Enter ya Space se menu open karein, links mein tab karein, aur Escape press karein. Agar in mein se koi cheez ajeeb behave kare, toh iska hal aksar missing focus style hota hai bajaye missing logic ke.

Features

Real breakpoint ke sath Mobile-first

Stacked layout default hai aur horizontal row enhancement hai, jo ke Tailwind ke responsive prefixes ke design ke mutabiq hai aur zaroorat se zyada overrides se bachata hai.

Sahi ARIA wiring

Toggle par aria-expanded aur aria-controls hain jo panel ke id ko point karte hain, taake assistive technology announce kar sake ke menu open hai aur yeh kis element ko control kar raha hai bajaye iske ke unlabeled button parh le.

Band karne ke liye Escape

Escape press karne se open menu band ho jata hai aur focus wapas toggle par aa jata hai, jo ke keyboard users sab se pehle try karte hain aur jo zyada tar copy-paste navbars mein nahi hota.

Panel remove kiya gaya hai, sirf hide nahi

Jab band ho, toh mobile links document se bilkul bahar hote hain, is liye invisible hone par na unmein tab kiya ja sakta hai aur na hi unhein parha ja sakta hai.

Mobile par baray tap targets

Stacked links mein desktop row ke muqable mein bara text aur zyada vertical padding hoti hai, jis se har target us size se upar rehta hai jise angootha aram se hit kar sakay.

Zero dependencies

Koi headless UI library nahi, koi animation package nahi, koi icon package nahi - hamburger aik inline SVG hai aur behavior chand lines ka state hai.

Common Uses

Marketing aur product sites

Landing page header ki standard shape: chand section links, aik logo, aur bar ke end par aik single conversion action.

Documentation sites

Docs sidebar ke upar top-level bar ke tor par kaam karta hai, jismein version switchers, search, aur repository ke links hote hain jabkay sidebar page tree ko handle karta hai.

Dashboards aur app shells

Logged-in app mein persistent top bar ke tor par kaam karta hai, jahan link row ki jagah workspace switchers hote hain aur call-to-action slot mein account menu hota hai.

Blogs aur publications

Top par category links aur end par subscribe action, phones par safai se collapse ho jata hai jahan zyada tar reading hoti hai.

Accessibility

Customization

Props

PropTypeDefaultDescription
links{ label: string; href: string }[][]Navigation links jo desktop row aur mobile panel dono mein render hote hain. Inhein saat items ya us se kam rakhein; is se zyada hone par dropdown ya mega menu behtar lagta hai.
logoReactNode-Default wordmark ko replace karta hai. Aik image, SVG, ya text pass karein - slot is baat ki pabandi nahi lagata ke is mein kya rakha jaye.
cta{ label: string; href: string }-Primary action jo bar ke end par aur mobile panel ke bottom par dikhaya jata hai. Sirf links wala navbar banane ke liye isay omit kar sakte hain.

Why Use These Responsive Navbars?

Ziyadatar copy-paste navbars screenshot mein theek lagne ke liye banaye jatay hain. Yeh wala un teen maslon se bachne ke liye banaya gaya hai jo production mein navbar ko kharab karte hain: aik link row jo breakpoint se pehle apne container se barh jaye, aik keyboard user jo jo kuch usne khola hai usay band na kar sakay, aur aik hidden panel jo abhi bhi tab order mein ho.

Is ki koi dependencies nahi hain. Aik headless UI library aapko focus management muft mein de degi, lekin yeh aapko track karne ke liye aik version, ship karne ke liye aik bundle, aur aik aisi component ke liye seekhne ke liye aik API bhi degi jo buniyadi tor par aik button aur aik list hai. Yahan poora behaviour us snippet mein nazar aata hai jo aap copy karte hain.

HTML aur React versions bilkul identical markup banatay hain, is liye static prototype mein approve hua design jab framework mein jata hai toh change nahi hota.

Tips

Frequently Asked Questions