Skip to content
  • No data uploaded
  • Instant results

Bootstrap 5 Navbar for Vanilla JS

A production-ready minimal navbar: a responsive top navigation bar with a logo, primary links, a sign-in/CTA pair on desktop and a collapsible hamburger menu on mobile. Pick your brand color, toggle dark mode and corner radius — the live preview and the Vanilla JS code update instantly in your browser.

Live component editor

Library
Framework
Style
Theme
Corner radius
Live preview
<!-- Requires Bootstrap 5.3 CSS + theme.css:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="theme.css"> -->
<header class="sticky-top top-0 z-1 bg-body border shadow-sm">
  <nav class="mw-6xl mx-auto px-4 py-2 d-flex align-items-center justify-content-between gap-4" aria-label="Main">
    <a href="#" class="d-flex align-items-center gap-2 fs-5 fw-bold text-decoration-none text-body-emphasis">
      <span class="badge rounded-pill bg-brand-subtle text-brand">◆</span> Acme
    </a>
    <div class="d-none d-md-flex align-items-center gap-4">
      <a href="#" class="small fw-medium text-decoration-none text-body">Product</a>
      <a href="#" class="small fw-medium text-decoration-none text-body">Solutions</a>
      <a href="#" class="small fw-medium text-decoration-none text-body">Pricing</a>
      <a href="#" class="small fw-medium text-decoration-none text-body">Docs</a>
    </div>
    <div class="d-none d-md-flex align-items-center gap-2">
      <a href="#" class="btn btn-link link-body-emphasis text-decoration-none fw-semibold rounded-2">Sign in</a>
      <a href="#" class="btn btn-brand fw-semibold rounded-2">Get started</a>
    </div>
    <button type="button" class="btn btn-link link-body-emphasis text-decoration-none fw-semibold rounded-2 d-md-none" aria-controls="mobile-menu" aria-label="Toggle menu" data-toggle="menu">☰</button>
  </nav>
  <div id="mobile-menu" data-show="menu" hidden>
    <div class="d-md-none px-4 pb-3 d-flex flex-column gap-1">
      <a href="#" class="btn btn-link link-body-emphasis text-decoration-none fw-semibold rounded-2">Product</a>
      <a href="#" class="btn btn-link link-body-emphasis text-decoration-none fw-semibold rounded-2">Solutions</a>
      <a href="#" class="btn btn-link link-body-emphasis text-decoration-none fw-semibold rounded-2">Pricing</a>
      <a href="#" class="btn btn-link link-body-emphasis text-decoration-none fw-semibold rounded-2">Docs</a>
      <a href="#" class="btn btn-brand fw-semibold rounded-2 mt-2">Get started</a>
    </div>
  </div>
</header>

<script>
  (() => {
    const state = { menu: false };
    const actions = {  };
    const pair = (s) => s.split(':');
    const sync = () => {
      document.querySelectorAll('[data-show]').forEach((el) => (el.hidden = !state[el.dataset.show]));
      document.querySelectorAll('[data-hide]').forEach((el) => (el.hidden = !!state[el.dataset.hide]));
      document.querySelectorAll('[data-when]').forEach((el) => { const [k, v] = pair(el.dataset.when); el.hidden = state[k] !== v; });
      document.querySelectorAll('[data-pressed]').forEach((el) => { const [k, v] = pair(el.dataset.pressed); el.setAttribute('aria-pressed', String(state[k] === v)); });
      document.querySelectorAll('[data-expanded]').forEach((el) => el.setAttribute('aria-expanded', String(!!state[el.dataset.expanded])));
    };
    document.addEventListener('click', (e) => {
      const t = e.target.closest('[data-toggle],[data-open],[data-close],[data-set],[data-call]');
      if (!t) return;
      const { toggle, open, close, set, call } = t.dataset;
      if (call) actions[call]?.(e);
      if (toggle) state[toggle] = !state[toggle];
      if (open) state[open] = true;
      if (close) state[close] = false;
      if (set) { const [k, v] = pair(set); state[k] = v; }
      sync();
    });
    sync();
  })();
</script>
All components →

Free Bootstrap 5 Navbar for Vanilla JS by pGento

Install Bootstrap 5 for Vanilla JS

Include Bootstrap 5.3 from the CDN (or npm install bootstrap) and the generated theme.css:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="theme.css">

Use the navbar in Vanilla JS

Paste the markup where the component should appear. The small inline <script> wires up the interactive state with one delegated click listener — no framework needed.

Accessibility & customization

Uses a <nav> landmark with aria-label, the menu button exposes aria-controls and aria-label, and links remain real <a> elements so keyboard and screen-reader navigation work without JavaScript.

Every color, radius and dark-mode choice is baked into plain Bootstrap classes plus a tiny CSS-variable theme file, so the copied code has no runtime dependency on this site.

Compatibility

ItemDetails
CSS frameworkBootstrap 5.3+ (CSS only)
LibraryPlain HTML + optional vanilla JS
Interactive statemenu
Dark modeYes — toggle in the editor
StyleMinimal

Frequently asked questions

How do I install this Bootstrap navbar in Vanilla JS?
Create a web page, install Bootstrap 5 as shown in the installation section, then paste the generated code. Also save the generated theme.css file.
Can I change the color of the navbar?
Yes. Use the brand color picker or type any hex code — the preview and code update instantly, and the color is written directly into the classes you copy.
Does the navbar support dark mode?
Yes. Toggle “Dark mode” in the editor to generate a dark palette version of the same component.
Is the navbar accessible?
Uses a <nav> landmark with aria-label, the menu button exposes aria-controls and aria-label, and links remain real <a> elements so keyboard and screen-reader navigation work without JavaScript.
Is this component free for commercial use?
Yes. The generated code is yours to use in personal and commercial projects without attribution.
Bootstrap 5 Navbar for Vanilla JS

Embed this tool on your site

Paste this code into any web page. It stays free, fast and ad-free inside your site.

Print or save as PDF

Prints just this tool and its result. Choose “Save as PDF” as the printer to get a file. Branding is stored only in this browser.