Webflow sync, pageviews & more.
NEW

How can I set the scroll offset on my Webflow page with a sticky navbar, since the offset is not automatically adjusted when using "position:sticky"?

TL;DR
  • Add top padding to each section equal to the navbar height or use a spacer div with an equal height and negative top margin to offset scroll position.
  • For dynamic navbar heights, disable Webflow’s default smooth scroll and implement custom JavaScript to control offset behavior.

When using a sticky navbar in Webflow, smooth scrolling to page sections doesn’t account for the navbar's height, causing content to appear hidden beneath it. Here's how to manually adjust the scroll offset.

1. Use Webflow's Built-In Section Linking

  • Webflow allows built-in smooth scrolling via section ID links (e.g., link to #about).
  • However, this method does not offset for sticky nav height, so additional steps are necessary.

2. Add Top Padding or Margin to Section Elements

  • Option 1: Top Padding

  • Add top padding to each section equal to or slightly more than your navbar’s height.

  • Example: If your navbar is 80px tall, set padding-top: 80px on the section.

  • This prevents content from being hidden beneath the navbar.

  • Option 2: Negative Margin Inside Spacer Div

  • Place an empty spacer div at the top of each section.

  • Set its height to match the navbar height, then apply a negative margin-top equal to that height.

  • Example: Spacer div height = 80px, margin-top = -80px.

3. Adjust with Custom JavaScript for Dynamic Offset (if needed)

If sections have dynamic content or the navbar height changes (e.g., responsive layouts or shrinking navs), use JavaScript for scroll offset compensation.

  • Embed a custom script in the Page Settings > Before tag:

  • Scroll with offset using scrollIntoView({ behavior: 'smooth' }) and modify the Y-position using window.scrollTo().

  • This requires assigning custom click handlers to your nav links.

  • If using this method, disable Webflow’s default smooth scroll:

  • Go to Project Settings > Custom Code > Footer Code and add:

    • Webflow.push(function() { $('a[href*="#"]').off('click'); });

Note: Exact JavaScript implementation depends on your structure. If you want a plug-and-play script, Webflow doesn’t provide one, so custom coding is necessary.

4. Avoid Using Position: Fixed for Scroll Offset Fixes

  • Some recommend switching to position: fixed and adding top padding to the entire page, but this can break layout behavior and isn’t necessary if manual offsets are done properly.

Summary

To fix content being hidden behind a sticky navbar, use top padding on sections equal to the navbar height or insert a spacer div with negative margin at the top of each section. For dynamic navbar heights, consider using custom JavaScript to apply scroll offsets manually.

Rate this answer

Other Webflow Questions