NAVIGATION

Sticky Navbar

A clean sticky navigation bar that stays visible at the top while the page scrolls. It uses simple HTML and CSS with smooth hover effects.

Scroll inside this preview

HTML
<nav class="sticky-navbar" aria-label="Primary Navigation">

  <a href="#" class="sticky-brand">
    &lt;/&gt; CodeRipple
  </a>

  <div class="sticky-nav-links">
    <a href="#">Home</a>
    <a href="#">Components</a>
    <a href="#">Playground</a>
    <a href="#">Blog</a>
  </div>

</nav>
CSS
.sticky-navbar{
  position:sticky;
  top:0;
  z-index:10;

  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:24px;

  padding:14px 20px;

  background:rgba(11,20,35,.94);
  border-bottom:1px solid #1c2a40;
  backdrop-filter:blur(12px);
}

.sticky-brand{
  color:#ffffff;
  font-weight:800;
  text-decoration:none;
}

.sticky-nav-links{
  display:flex;
  align-items:center;
  gap:20px;
}

.sticky-nav-links a{
  color:#aab4c8;
  font-size:14px;
  font-weight:600;
  text-decoration:none;
  transition:color .25s ease;
}

.sticky-nav-links a:hover{
  color:#22d3ee;
}

How This Sticky Navbar Works

The Sticky Navbar is a lightweight navigation component that stays attached to the top of its scrolling container. Its HTML uses a semantic nav element with an aria-label of “Primary Navigation,” followed by a CodeRipple brand link and four navigation links: Home, Components, Playground, and Blog.

The sticky behavior comes entirely from CSS. The .sticky-navbar rule uses position: sticky together with top: 0. The top value defines the point where the navbar should remain fixed relative to its scrolling context. Unlike a permanently fixed element, a sticky element behaves according to its normal document position until the relevant scrolling threshold is reached.

A z-index of 10 keeps the navbar above nearby content while it is sticking. This is particularly useful when page content scrolls underneath the navigation area. For a detailed explanation of this positioning behavior, see the MDN position documentation.

Inside the navbar, Flexbox controls the horizontal layout. display: flex and align-items: center vertically align the brand and links, while justify-content: space-between pushes them toward opposite sides. A 24px gap provides additional spacing when necessary.

The navbar uses 14px 20px padding to give the content enough vertical and horizontal room. Its background is rgba(11,20,35,.94), making it slightly transparent rather than using a fully opaque dark surface. The backdrop-filter: blur(12px) applies blur to content visible behind that translucent background, helping maintain separation as page content passes underneath.

A 1px solid #1c2a40 border is placed along the bottom edge. Instead of surrounding the entire navbar with a border, this creates a simple visual boundary between the navigation and the content below it.

The .sticky-brand link uses white text and a font weight of 800. Its default underline is removed with text-decoration: none. Unlike some other CodeRipple navigation components, the </> portion and CodeRipple name are contained within the same anchor and use the same text color.

The navigation links are grouped inside .sticky-nav-links, which is another flex container. It uses a 20px gap to separate Home, Components, Playground, and Blog. Individual links use the muted #aab4c8 color, a 14px font size, and a font weight of 600.

Hover feedback is intentionally simple. Each navigation link has a color .25s ease transition. On hover, the text changes from its muted default to cyan #22d3ee. No background, underline, transform, or additional animation is applied.

This Sticky Navbar does not use JavaScript. Its published JavaScript field is empty, so the sticky positioning and hover behavior are handled entirely through CSS. It also does not include a responsive media query, mobile hamburger menu, scroll event handler, active-link logic, or scroll-dependent style changes.

Because position: sticky depends on the surrounding scrolling layout, the navbar’s behavior is also influenced by where the component is placed and which ancestor provides its scrolling context. The component itself simply defines the sticky element and its top offset.

Customizing the Sticky Navbar

The component has a small set of CSS and HTML values, making its appearance and navigation labels straightforward to adapt.

  • Replace </> CodeRipple with the brand name or text required by your website.
  • Change Home, Components, Playground, and Blog to match your primary navigation destinations.
  • Modify top: 0 if the navbar needs to stick below another element rather than directly at the top.
  • Adjust z-index: 10 when the navbar needs to sit above or below other positioned interface elements.
  • Change rgba(11,20,35,.94) to control the navbar’s background color and transparency.
  • Adjust blur(12px) to increase or decrease the backdrop blur effect.
  • Modify the 20px navigation-link gap or the 24px main flex gap to change horizontal spacing.
  • Replace the cyan #22d3ee hover color with an accent color that matches your interface.

Where to Use This Sticky Navbar

A sticky navigation bar is useful on pages where important navigation links should remain readily available while visitors move through longer content.

  • Documentation and tutorial pages
  • Blogs with long articles
  • Component libraries
  • Developer resource websites
  • Landing pages with multiple sections
  • Content-heavy website layouts

Because this implementation has only four links and no JavaScript behavior, it works best when a simple persistent navigation row is enough. For a layout that switches to a dedicated menu control on smaller screens, the Hamburger Menu Navbar provides a related responsive navigation approach.

Frequently Asked Questions

Does the Sticky Navbar use JavaScript?

No. The component’s JavaScript is empty. Its sticky behavior is implemented entirely with the CSS position: sticky property and top: 0.

What makes the navbar stay at the top?

The .sticky-navbar element uses position: sticky and top: 0. These properties tell the browser to keep the navigation at the top boundary of its relevant scrolling context when the sticky threshold is reached.

Does the Sticky Navbar change when the page is scrolled?

There is no JavaScript scroll listener or separate scrolled class in this component. Its background, border, blur, and other visual styles remain defined by the same CSS rules.

Is the Sticky Navbar responsive?

The layout uses Flexbox and spacing properties, but the supplied CSS does not contain a responsive media query. There is no mobile hamburger menu or alternate small-screen layout included.

The Sticky Navbar keeps its implementation focused: semantic navigation markup, CSS sticky positioning, a translucent blurred background, and simple hover transitions provide persistent navigation without requiring JavaScript.

Scroll to Top