5 min read
webdev youtube

Create a Sticky Glassmorphism Navbar with Tailwind CSS and DaisyUI

A sticky glassmorphism navbar adds a modern, polished feel to any website. This guide walks through building one using DaisyUI’s navbar component and Tailwind CSS v4’s backdrop utilities.

Starting with DaisyUI Navbar

DaisyUI provides a ready-made responsive navbar with a dropdown menu, navigation links, and a call-to-action button. Here’s the base structure:

<div class="navbar bg-base-100">
<div class="navbar-start">
<div class="dropdown">
<div tabindex="0" role="button" class="btn btn-ghost lg:hidden">
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16" />
</svg>
</div>
<ul tabindex="0" class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52">
<li><a>Home</a></li>
<li><a>About</a></li>
<li><a>Contact</a></li>
</ul>
</div>
<a class="btn btn-ghost text-xl">MyApp</a>
</div>
<div class="navbar-center hidden lg:flex">
<ul class="menu menu-horizontal px-1">
<li><a>Home</a></li>
<li><a>About</a></li>
<li><a>Contact</a></li>
</ul>
</div>
<div class="navbar-end">
<a class="btn btn-primary">Get Started</a>
</div>
</div>

Adding the Glassmorphism Effect

The glass effect requires two key properties: transparency and backdrop blur.

Background Opacity

Use a semi-transparent background color. In Tailwind v4, you can use arbitrary values or custom colors:

<div class="navbar bg-sky-500/10">

The /10 sets the opacity to 10%, making the background slightly visible behind the navbar. Adjust this value to match your theme.

Backdrop Blur

The backdrop-blur class creates the frosted glass look:

<div class="navbar bg-sky-500/10 backdrop-blur-md">

Without both opacity and blur, the glassmorphism effect won’t be visible.

Making It Sticky

Three classes work together to keep the navbar fixed:

ClassPurpose
stickyPositions element relative until scroll threshold
top-3Keeps navbar slightly below screen top
z-10Ensures navbar stays above other elements
<div class="navbar bg-sky-500/10 backdrop-blur-md sticky top-3 z-10">

The sticky value behaves like relative until the element reaches the specified top position, then behaves like fixed.

Adding Rounded Corners

For a softer, modern look, add rounded-md:

<div class="navbar bg-sky-500/10 backdrop-blur-md sticky top-3 z-10 rounded-md">

Complete Example

<div class="navbar bg-sky-500/10 backdrop-blur-md sticky top-3 z-10 rounded-md mx-4 mt-2">
<div class="navbar-start">
<div class="dropdown">
<div tabindex="0" role="button" class="btn btn-ghost lg:hidden">
<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h8m-8 6h16" />
</svg>
</div>
<ul tabindex="0" class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100/80 backdrop-blur-sm rounded-box w-52">
<li><a>Home</a></li>
<li><a>About</a></li>
<li><a>Contact</a></li>
</ul>
</div>
<a class="btn btn-ghost text-xl">MyApp</a>
</div>
<div class="navbar-center hidden lg:flex">
<ul class="menu menu-horizontal px-1">
<li><a>Home</a></li>
<li><a>About</a></li>
<li><a>Contact</a></li>
</ul>
</div>
<div class="navbar-end">
<a class="btn btn-primary">Get Started</a>
</div>
</div>

Note the dropdown menu also uses bg-base-100/80 backdrop-blur-sm for consistency.

Customization Options

All these classes are flexible. Consider:

  • Colors: Change bg-sky-500/10 to match your theme (e.g., bg-primary/10)
  • Blur intensity: Use backdrop-blur-sm, backdrop-blur, backdrop-blur-md, backdrop-blur-lg, or backdrop-blur-xl
  • Spacing: Adjust top-3 to top-0, top-4, or remove entirely
  • Border radius: Try rounded-box, rounded-xl, or rounded-2xl
  • Animations: Add transition-all duration-300 for smooth hover effects
<div class="navbar bg-primary/10 backdrop-blur-lg sticky top-0 z-10 rounded-box transition-all duration-300 hover:bg-primary/20">

Summary

PropertyTailwind ClassEffect
Transparencybg-{color}/{opacity}Semi-transparent background
Blurbackdrop-blur-{size}Frosted glass appearance
Positionsticky top-{value}Fixed on scroll
Layer orderz-{value}Above other content
Shaperounded-{size}Softened corners

This post generated by opencode with GLM-5 from Z.AI Coding Plan, based on content from: https://www.youtube.com/watch?v=8ap48AJC7oo