Webflow

How to Build a Sticky Navbar That Shrinks on Scroll in Webflow (No Code Needed)

TS Talha Shahzad··9 min read
The short version
  • Native Webflow interactions handle shrinking navbars in 90% of cases
  • Custom code is only needed when the nav height changes responsively
  • Sticky navs break anchor link scroll offset, so always compensate
  • Test on mobile where sticky navs eat significant screen height
  • Animate logo size and padding as separate classes for clean control

You can build a sticky shrinking navbar in Webflow using nothing but native interactions. No custom JavaScript, no third-party libraries, no embed hacks. The "While scrolling in view" trigger handles the animation, and position sticky keeps the nav locked to the top.

Most tutorials jump straight to custom code for this effect. That is almost always unnecessary. After building 450+ Webflow sites, I can tell you that native interactions cover about 90% of shrinking navbar use cases. The only time I reach for JavaScript is when the nav height changes responsively in ways that the interaction timeline cannot predict.

Here is exactly how to build it, step by step.

Set Up the Navbar Structure

Before you touch any interactions, get the HTML structure right. This matters more than people think.

Create a Section element at the top of your page. Inside it, place a Container or a Div Block for your nav content. Inside that, add your logo (as an image or link block), your nav links, and your CTA button.

Do not use the default Webflow Navbar component if you want full control over the shrink animation. The native Navbar component has built-in hamburger logic that can conflict with scroll animations. A custom-built nav using Div Blocks gives you cleaner control over every property.

Set the outer Section to position: sticky, top: 0, and give it a z-index of 999 or higher. That pins it to the viewport ceiling as you scroll.

Give the Section an initial padding of something like 24px top and bottom. This is what you will animate down to create the shrink effect.

Build the Shrink Animation with Native Interactions

Here is where the magic happens, and it is surprisingly simple.

  1. Select the Section directly below your navbar (the hero or the first content section).
  2. Open the Interactions panel and add a new "While scrolling in view" trigger on that section.
  3. In the animation timeline, add your navbar Section as the target element.
  4. Set two keyframes for padding: at 0% scroll, keep padding at 24px. At maybe 15-20% scroll, set padding to 8px.
  5. Add keyframes for your logo image: at 0%, keep it at its original size (say 48px height). At 15-20%, shrink it to 32px.

The scroll percentage is relative to the trigger section moving through the viewport. So 15-20% means the shrink completes quickly as you start scrolling, which feels natural.

A few details that make this feel polished:

  • Add a background color opacity change. Start with a slightly transparent background and transition to fully opaque as the nav shrinks. This gives the nav visual weight once it is compact.
  • Animate box-shadow from none to a subtle shadow (0 2px 8px rgba(0,0,0,0.08)) so the nav visually separates from the content below.
  • Set the easing to ease-out for a smooth deceleration.

Why Native Interactions Beat Custom Code Here

I want to explain why I push native interactions so hard on this particular effect.

Webflow's scroll interaction runs on the compositor thread in most browsers. That means it does not block the main thread and performs well even on mid-range phones. When you write custom JavaScript to listen to the scroll event, you are running on the main thread by default. Without requestAnimationFrame throttling and careful optimization, you get janky scrolling.

Native interactions also survive Webflow updates. Custom code can break when Webflow changes class naming conventions or re-renders the DOM. I have seen this happen on client sites where the shrinking nav stopped working after a Webflow editor update because the JavaScript was targeting a class that got renamed.

The only scenario where I use custom code is when the nav height is dynamic. For example, if a notification bar sits above the nav and gets dismissed, or if the nav contains a mega menu whose height changes. In those cases, you need JavaScript to calculate the actual height and adjust offsets dynamically. For a standard marketing site nav, skip the code entirely.

Handle the Logo and Padding as Separate Animations

A common mistake is trying to animate everything in one interaction. Split your animations into separate actions within the same timeline.

Create one set of keyframes for the Section padding. Create another set for the logo height. And if you are changing font size on nav links, create a third set.

Why? Because you might want different timing. The padding can shrink linearly, but the logo might look better with a slight delay so it does not feel like everything collapses at once. Staggering by even 2-3% on the scroll timeline makes the animation feel intentional rather than mechanical.

Here is a setup I use often:

  • 0-10% scroll: padding shrinks from 24px to 8px
  • 5-15% scroll: logo shrinks from 48px to 32px
  • 5-12% scroll: background goes from transparent to solid
  • 8-15% scroll: box-shadow fades in

That slight overlap creates a cascading feel. It takes 30 seconds longer to set up than doing everything at once, and it looks noticeably better.

This is the part nobody warns you about until it is too late.

When you have a sticky nav and you use anchor links (jump links to sections on the same page), the browser scrolls the target element to the very top of the viewport. That means it lands behind your nav. Your users click a link, and the heading they expected to see is hidden under 60-80 pixels of navbar.

The cleanest fix is CSS, not JavaScript. Add this to your page or site custom code:

html {
  scroll-padding-top: 80px;
}

Replace 80px with your nav's height. If your nav shrinks from 96px to 56px, use the shrunk height (56px) plus a little buffer, so around 64px. The user will be scrolling when they click an anchor link, meaning the nav will already be in its shrunk state.

I wrote a full breakdown of this fix in my post on fixing anchor links with sticky navbars if you want the deep dive.

Want a website that turns visitors into customers, not just compliments?

Book a 15-min intro

Test on Mobile Where Sticky Eats Screen Height

Here is a real-world number that might change your design decisions. On an iPhone SE (375x667 viewport), a sticky nav at 60px tall takes up 9% of the screen. If that nav only shrinks to 48px, you are still losing 7% of the viewport to navigation at all times.

That might be fine for a marketing site where the nav has a strong CTA. It is not fine for a long-form blog post where reading space matters.

I recommend these mobile adjustments:

  1. Shrink the nav more aggressively on mobile. If your desktop nav goes from 80px to 56px, your mobile nav should go from 60px to 44px.
  2. Consider hiding the nav entirely on scroll-down and showing it on scroll-up. This is a separate interaction ("While page is scrolling" with direction conditions), but it is worth the effort on content-heavy pages.
  3. Always test on actual devices, not just the Webflow preview. The preview does not perfectly simulate mobile scroll behavior, and touch scrolling has different momentum than mouse scrolling.

Add the Custom Code Version (Only When You Need It)

If your nav height truly is dynamic, meaning it changes based on content that is not predictable at design time, here is the JavaScript approach I use.

Add this to the before-body custom code area of your page:

<script>
  const nav = document.querySelector('[data-nav="main"]');
  let lastScroll = 0;

  window.addEventListener('scroll', () => {
    const currentScroll = window.pageYOffset;
    if (currentScroll > 50) {
      nav.classList.add('nav-scrolled');
    } else {
      nav.classList.remove('nav-scrolled');
    }
    lastScroll = currentScroll;
  });
</script>

Then in Webflow, create a combo class called "nav-scrolled" with the reduced padding, smaller logo, and any other style changes. Add a CSS transition on the base nav class so the swap is smooth:

[data-nav="main"] {
  transition: padding 0.3s ease, background-color 0.3s ease;
}

This approach is more fragile than native interactions. You need to maintain the custom code, it runs on the main thread, and it introduces a dependency that someone else on the team might not understand. Use it only when native interactions genuinely cannot do the job.

Combine with a Nav Color Swap for Dark Sections

A shrinking nav gets even better when you pair it with a color-aware navigation. If your page alternates between light and dark sections, you can swap the nav's text color and background based on which section is currently behind it.

I covered this technique in detail in my post about section background color changes on scroll. The short version: use a "While scrolling in view" interaction on each dark section to toggle a class on the nav that inverts its colors.

When you combine the shrink effect with a color swap, the nav feels like it truly belongs to the page rather than just sitting on top of it. It is one of those details that separates a good Webflow build from a forgettable one.

Common Mistakes I See on Client Sites

After reviewing hundreds of Webflow projects through my white-label development service, these are the most frequent shrinking-nav mistakes:

  1. Forgetting initial appearance. If you do not set "initial appearance" in the interaction settings, the first load can show the shrunk state briefly before expanding. Always set the initial state explicitly.
  2. Animating height instead of padding. Animating the height property can cause layout shifts that affect content below the nav. Animate padding instead, and let the height follow naturally.
  3. Not testing with the hamburger menu. On mobile, if your hamburger menu opens a full-screen overlay, the shrunk nav state can make the close button too small to tap. Test both states.
  4. Ignoring the back-to-top scroll. Users who scroll back to the top should see the nav expand again smoothly. If your animation only triggers on scroll-down, the nav stays shrunk forever. The "While scrolling in view" interaction handles this automatically, which is another reason to prefer it over custom code.

Wrapping Up

A sticky shrinking navbar is one of those effects that looks complex but is genuinely straightforward in Webflow when you use native interactions. Start with position sticky, build the scroll animation on the section below the nav, and stagger your keyframes for a polished feel.

Save the custom code for the edge cases where nav height is truly dynamic. For everything else, Webflow's built-in tools do the job faster, cleaner, and with better performance.

If you want me to build this for your site, or if you are an agency looking for a white-label Webflow partner who handles these details, get in touch and I will take it from there.

Prefer to hire through Upwork?
Top Rated Plus, 100% Job Success, 450+ projects shipped. See the reviews and start a contract.
Hire me on Upwork

FAQ

Can I make a Webflow navbar shrink on scroll without custom code?

Yes. Webflow's native 'While scrolling in view' interaction lets you animate padding, logo size, and background on scroll without any JavaScript.

Why do my anchor links scroll behind the sticky navbar?

Position sticky does not auto-adjust scroll offset. Add scroll-margin-top to your anchor targets or scroll-padding-top to the body to compensate for the nav height.

Does a sticky shrinking navbar hurt mobile performance?

Not if you keep animations simple. But do test on small screens because a sticky nav can eat 15-20% of viewport height, especially before the shrink triggers.

Should I use position sticky or fixed for a shrinking navbar?

Use position sticky in almost every case. Fixed positioning requires manual offset for all page content and creates more layout headaches.

All posts
the next step is small

Want a site that does this for you?

15 minutes, no deck, no pressure. Worst case, you leave with a free plan.

keep reading

More notes