Add

Lorem ipsum

Lorem ipsum

A
A
A
Design

4 views

5 min

How to Create a Sticky Navbar That Changes Style on Scroll in Webflow

Learn how to create a sticky navbar that changes style on scroll in Webflow with a lightweight JavaScript script.

In this tutorial, Sandro, cofounder of the Gemeos Webflow agency, shows you how to create a sticky navbar that changes style on scroll in Webflow, without any external library.

Example

Scroll in the area to see the navbar change

↓ Scroll here

Welcome to Gemeos. We build high-performance Webflow websites for startups and scale-ups that want a digital presence worthy of their ambitions.

Our approach combines design, Webflow development, and SEO strategy for measurable results. Every project is built to convert.

Keep scrolling to see the navbar change appearance after 50px of scrolling.

ApproachMethodBenefit
Native Webflow CSSPosition: sticky + class on scrollNo JS needed if the style stays fixed
JS + CSS class (this tutorial)Script that adds a class on scrollDynamic style changes
Webflow InteractionsScroll animation on the navbarVisual only in the Designer

1. Create your navbar and assign it a class

In the Designer, select your Navbar. Give it the class navbar. Set its position to Fixed at the top of the page.

2. Create a "scrolled" state in your styles

In your global styles, create a navbar.scrolled variant with the properties you want: opaque background, drop shadow, reduced height. Example: background-color: #fff, box-shadow: 0 2px 8px rgba(0,0,0,0.1).

3. Add this script to the <body> of your page

Go to Page Settings > Before </body> tag and paste the following script.

const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', function {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});

4. Publish and test

Publish your site and scroll: the scrolled class is added as soon as you hit 50px of scrolling. Adjust the 50 value to fit your design.

good to know

To avoid a flash on load on pages that are already scrolled (for example, when using the browser back button), add an immediate call to the scroll function on load: window.dispatchEvent(new Event('scroll')); after defining the listener.

Conclusion

Your navbar now changes style smoothly on scroll. Use cases:

  • Transparent navbar on the hero that becomes opaque on scroll
  • Reduce the navbar height to save space
  • Change the logo color from light to dark

Good to know

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet consectetur.

Lorem ipsum dolor sit amet consectetur. Aliquam orci sagittis dignissim sapien praesent donec.

Lorem ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Published on

You might be interested in these tutorials

Similar tutorials

SEO / GEO

5 min read

5 views

How to Set Up a Redirect in Webflow? (2026)

Updated on 19.12.2025 by Sandro DA SILVA

SEO / GEO

5 min read

5 views

Add structured data to your Webflow site?

Updated on 21.08.2025 by Sandro DA SILVA

No-code

5 min read

5 views

How to Obfuscate a Link in Webflow

Updated on 23.04.2025 by Sandro DA SILVA

Let’s f*****G GO !!

Ready to launch
Your business?

Alexandre

Max

Enora

Bryan

Cannelle

Tiphaine

You'll :heart: our collaboration...