- No data uploaded
- Instant results
Tailwind CSS Navbar for Vanilla JS — Glassmorphism
A production-ready glassmorphism 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
<!-- Requires Tailwind CSS v3 (CLI/PostCSS build, or the Play CDN for prototypes) -->
<header class="sticky top-0 z-10 bg-white/60 backdrop-blur-xl border border-white/60 shadow-2xl">
<nav class="max-w-6xl mx-auto px-6 py-3 flex items-center justify-between gap-6" aria-label="Main">
<a href="#" class="flex items-center gap-2 text-lg font-bold no-underline text-slate-900">
<span class="inline-flex items-center px-2.5 py-0.5 text-xs font-semibold rounded-full bg-[#4f46e5]/10 text-[#4f46e5]">◆</span> Acme
</a>
<div class="hidden md:flex items-center gap-6">
<a href="#" class="text-sm font-medium no-underline text-slate-700">Product</a>
<a href="#" class="text-sm font-medium no-underline text-slate-700">Solutions</a>
<a href="#" class="text-sm font-medium no-underline text-slate-700">Pricing</a>
<a href="#" class="text-sm font-medium no-underline text-slate-700">Docs</a>
</div>
<div class="hidden md:flex items-center gap-2">
<a href="#" class="inline-flex items-center justify-center px-3 py-2 text-sm font-semibold rounded-lg transition-colors text-slate-700 hover:bg-slate-900/5">Sign in</a>
<a href="#" class="inline-flex items-center justify-center px-4 py-2.5 text-sm font-semibold rounded-lg bg-[#4f46e5] hover:bg-[#433cc3] text-white shadow-sm transition-colors focus:outline-none focus:ring-2 focus:ring-[#4f46e5] focus:ring-offset-2 focus:ring-offset-white">Get started</a>
</div>
<button type="button" class="inline-flex items-center justify-center px-3 py-2 text-sm font-semibold rounded-lg transition-colors text-slate-700 hover:bg-slate-900/5 md:hidden" aria-controls="mobile-menu" aria-label="Toggle menu" data-toggle="menu">☰</button>
</nav>
<div id="mobile-menu" data-show="menu" hidden>
<div class="md:hidden px-6 pb-4 flex flex-col gap-1">
<a href="#" class="inline-flex items-center justify-center px-3 py-2 text-sm font-semibold rounded-lg transition-colors text-slate-700 hover:bg-slate-900/5">Product</a>
<a href="#" class="inline-flex items-center justify-center px-3 py-2 text-sm font-semibold rounded-lg transition-colors text-slate-700 hover:bg-slate-900/5">Solutions</a>
<a href="#" class="inline-flex items-center justify-center px-3 py-2 text-sm font-semibold rounded-lg transition-colors text-slate-700 hover:bg-slate-900/5">Pricing</a>
<a href="#" class="inline-flex items-center justify-center px-3 py-2 text-sm font-semibold rounded-lg transition-colors text-slate-700 hover:bg-slate-900/5">Docs</a>
<a href="#" class="inline-flex items-center justify-center px-4 py-2.5 text-sm font-semibold rounded-lg bg-[#4f46e5] hover:bg-[#433cc3] text-white shadow-sm transition-colors focus:outline-none focus:ring-2 focus:ring-[#4f46e5] focus:ring-offset-2 focus:ring-offset-white 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>
More Tailwind components for Vanilla JS
All components →- Footer A multi-column site footer with a brand description, three link groups, a newsletter sign-up field and a copyright row
- Hero Section A landing-page hero with an announcement badge, a large headline, supporting copy, primary and secondary calls to action and a row of social-proof stats
- Login Modal A centered sign-in dialog with email and password fields, “remember me”, a forgot-password link and a social sign-in button
- Cookie Consent Banner A GDPR-style cookie banner with equally prominent “Accept all” and “Reject all”, granular analytics/marketing toggles (off by default), stored consent and Google Consent Mode v2 signals
- Feature Grid A marketing section with a centered heading and a responsive grid of six feature cards, each with an icon badge, title and description
- Signup Form A registration card with name, email and password fields, a password hint, a terms-of-service checkbox and a primary call to action
- Pricing Table A three-tier pricing section with a monthly/yearly billing toggle, a highlighted “most popular” plan and feature checklists
- Contact Form A contact card with name, email, a topic selector, a message textarea and a submit button
Install Tailwind CSS for Vanilla JS
Prototype instantly with the Play CDN, or install the Tailwind CLI for production:
<script src="https://cdn.tailwindcss.com"></script>npm install -D tailwindcss@3
npx tailwindcss init
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watchAdd ./**/*.html to content in tailwind.config.js and put the three @tailwind directives in src/input.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 utility classes, so the copied code has no runtime dependency on this site. The glass style relies on backdrop-filter, supported in all current browsers; place it over a colorful background for the best effect.
Compatibility
| Item | Details |
|---|---|
| CSS framework | Tailwind CSS v3.4+ |
| Library | Plain HTML + optional vanilla JS |
| Interactive state | menu |
| Dark mode | Yes — toggle in the editor |
| Style | Glassmorphism (backdrop blur) |