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
  • Use spacer divs with negative top margin or apply padding plus negative margin to offset sticky navbar height when linking to anchor sections.  
  • For dynamic navbar heights, implement custom JavaScript to adjust scroll behavior, ensuring the navbar is positioned outside target sections.

Sticky navbars in Webflow don’t automatically offset section links, causing anchor-linked content to appear hidden beneath the sticky navbar. Here’s how to fix the scroll offset manually.

1. Use Spacer Divs with Negative Margin

  • Add a spacer div right before each target section that links scroll to.
  • Set the spacer height to match the height of your sticky navbar.
  • Apply a negative top margin equal to the height of the spacer to cancel out added space.
  • Example: If your navbar is 80px high, the spacer should be height: 80px and margin-top: -80px.

2. Add Padding to Sections (Alternative Approach)

  • Instead of spacer divs, you can apply top padding to each section equal to the navbar’s height.
  • Then apply an equivalent negative top margin to bring the section visually back in line.
  • This method keeps your structure cleaner without extra elements.

3. Use Custom Code for Dynamic Offset Adjustment

If your navbar height changes (e.g., responsive sizes), use custom JS to adjust anchor scroll behavior:

  • Create a script that adds offset when clicking anchor links.
  • Example: Use scrollIntoView({ behavior: 'smooth', block: 'start' }) with a manual offset using scrollTo.

Important: Avoid raw code per guidelines but use custom scripts via Page Settings > Custom Code or Embed if needed.

4. Ensure Navbar Is Not Inside the Section

  • Make sure the sticky navbar is outside and above the sections it's linking to.
  • If the navbar is inside the same section, offsets won't function properly.

Summary

To fix anchor scroll offset with a sticky navbar in Webflow, apply a spacer div with negative margin or use padding and negative margin directly on target sections. For dynamic setups, add custom JavaScript scroll offset behavior.

Rate this answer

Other Webflow Questions