Webflow sync, pageviews & more.
NEW

How can I fix the issue of having a small amount of background image below the fold on mobile browsers in Webflow? I have tried using custom CSS and JavaScript codes, but it did not work.

TL;DR
  • Avoid using 100vh directly; instead, use JavaScript to dynamically set a --vh custom property based on window.innerHeight.
  • Apply this custom height to sections using height: calc(var(--vh, 1vh) * 100), and ensure no extra spacing from margins, padding, or overflow settings in your layout.

You're seeing a small gap of background image below the fold on mobile browsers due to mobile viewport rendering inconsistencies, especially on iOS Safari. This usually occurs when using 100vh for height.

1. Understand Why 100vh Causes Issues on Mobile

  • On mobile browsers, 100vh doesn't always represent the actual visible area due to the browser’s dynamic UI (like the address bar).
  • This causes extra space to be rendered, which can show a sliver of the background image below or above fold when scrolling or resizing.

2. Use Webflow's Min-Height with Caution

  • In Webflow, if you've used Height: 100vh or set a section to Height: 100% + VH unit, it's likely to break layout consistency on mobile.
  • Instead, use Min Height: 100vh only when necessary and monitor behavior on real devices.

3. Use JavaScript to Set Correct Height

Since CSS solutions can be inconsistent, use JavaScript to calculate viewport height dynamically and apply it.

  • Create a custom height variable that calculates the effective viewport height:

  • Go to Page Settings > Before tag, and paste:

    const setVh = () => { document.documentElement.style.setProperty('--vh', window.innerHeight * 0.01 + 'px'); }; setVh(); window.addEventListener('resize', setVh);

  • Then, in Webflow Designer, use that in a custom style tag via Embed component or Site-wide CSS:

  • Add a class like .full-screen-fix and apply:
    height: calc(var(--vh, 1vh) * 100);

4. Apply the CSS Fix in Webflow Designer

  • Add a custom class to your section (e.g., hero-section).

  • Add an Embed element on your page containing:

    <style> .hero-section { height: calc(var(--vh, 1vh) * 100); } </style>

  • This ensures your section respects the actual visible height, avoiding scroll gaps.

5. Avoid Overflow Issues

  • Ensure there are no unintended margins or padding on your body or section elements that could create extra space.

  • Set Body and html to have:

  • Overflow: hidden

  • Margin and padding: 0

Summary

To fix extra space caused by background image rendering below the fold on mobile, avoid hardcoded 100vh, and instead dynamically calculate viewport height using JavaScript, then apply that using CSS (calc(var(--vh, 1vh) * 100)). This results in a more reliable layout on mobile devices.

Rate this answer

Other Webflow Questions