How to Build a Frosted Glass Sticky Navbar with React and CSS
A frosted glass navigation bar is a subtle, modern design element that can elevate a website’s aesthetics without sacrificing usability. This technique is used by design-forward companies like Apple and Vercel to create clean, elegant interfaces that support both light and dark themes.
In this post, we’ll build a sticky frosted glass navbar from scratch using just React and vanilla CSS—no libraries or frameworks.
Why Use a Frosted Glass Effect?
The frosted glass effect enhances UX by maintaining background context while foreground elements remain readable and distinct. It works especially well in modern, scrollable layouts and looks natural over gradients, images, or hero sections.
Common use cases include:
- Sticky headers on landing pages
- Overlays on video or image backgrounds
- UI elements that need to retain visual depth without hard borders
Key Concepts
The frosted glass effect is implemented using a few core CSS properties:
backdrop-filter: blur(...)
: applies a blur to whatever is behind the element.background-color: rgba(...)
: creates a translucent layer over the blurred content.position: fixed
: keeps the navbar pinned at the top of the viewport.- Dark mode support via
prefers-color-scheme
for theme-aware styling.
Let’s walk through a working implementation.
Step-by-Step: React + CSS Implementation
React Component
We’ll create a basic layout with a sticky header and scrollable content.
import React from "react";
import "./styles.css";
export default function App() {
return (
<>
<header className="navbar">
<h1>Tom Newton</h1>
<nav>
<a href="#about">About</a>
<a href="#projects">Projects</a>
<a href="#contact">Contact</a>
</nav>
</header>
<main>
<section>
<h2>Welcome to My Website</h2>
<p>This is some scrollable content behind the frosted navbar.</p>
{[...Array(25)].map((_, i) => (
<p key={i}>More content line {i + 1}</p>
))}
</section>
</main>
</>
);
}
CSS Styling This is where the visual effect happens. We’ll apply blur, translucency, and layout rules to make the navbar responsive and modern.
body {
margin: 0;
font-family: system-ui, sans-serif;
background: linear-gradient(to bottom, #e3f2fd, #ffffff);
color: #222;
}
.navbar {
position: fixed;
top: 0;
width: 100%;
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
background-color: rgba(255, 255, 255, 0.6);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px); /* Safari support */
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
z-index: 1000;
}
nav a {
margin-left: 1.5rem;
text-decoration: none;
color: #333;
font-weight: 500;
}
main {
padding-top: 100px;
}
Supporting Dark Mode
With just a few extra rules, we can ensure the UI feels natural in both light and dark environments.
@media (prefers-color-scheme: dark) {
body {
background: linear-gradient(to bottom, #0f172a, #1e293b);
color: #ddd;
}
.navbar {
background-color: rgba(0, 0, 0, 0.4);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
color: white;
}
nav a {
color: #eee;
}
nav a:hover {
color: #4ade80;
}
}
Best Practices and Considerations
Performance: backdrop-filter can impact GPU performance on low-powered devices. Avoid applying it to large or highly dynamic regions.
Compatibility: Ensure -webkit-backdrop-filter is used for Safari support.
Z-index management: Sticky headers should have a high z-index to prevent being overlapped by other elements.
Accessibility: Maintain clear contrast and avoid relying solely on visual effects for navigation cues.
Final Thoughts
The frosted glass sticky navbar is a simple yet effective pattern that can enhance both form and function in a web interface. With a small amount of CSS and no external libraries, you can create an interface that feels high-end and refined. It adapts well to both themes and screen sizes, making it a versatile tool in any frontend developer’s toolkit.
Live Demo
You can test this implementation here: 👉 View on CodeSandbox