Webflow sync, pageviews & more.
NEW

What is the workaround for VH and VW not functioning correctly in Safari 5.1 when using Webflow?

TL;DR
  • Replace vh/vw with % or px units in Webflow layouts to ensure compatibility with Safari 5.1.
  • Use custom classes, JavaScript to set dynamic heights, and embed custom CSS fallbacks via Webflow's Page Settings or Embed elements.

Safari 5.1 has limited support for modern CSS units like vh and vw, which can cause layout issues in Webflow projects. Here's how to work around those limitations.

1. Understand the Limitation

  • Safari 5.1 (released in 2011) lacks full support for vh and vw, particularly:
  • vh includes hidden browser UI elements on mobile, creating miscalculations.
  • JavaScript and older CSS fallbacks are typically needed.
  • Webflow's built-in tools rely on modern browser support, so manual fixes are required.

2. Avoid vh and vw Where Possible

  • Use percentage-based height/width (%) for sections and containers instead of viewport units.
  • Example: Use Height: 100% instead of Height: 100vh on sections inside the body tag.

3. Use Fallbacks with CSS Classes

  • In Webflow, create a custom class for elements that typically use vh or vw.
  • Apply padding or margins in % or px values instead of relying solely on viewport units.
  • Set minimum heights using pixel values if consistent layout is critical.

4. Apply Custom Code for JS-Based Fix

  • Use JavaScript in Page Settings → Before tag to dynamically set height for affected elements:
  • Example: Use document.documentElement.clientHeight or window.innerHeight to calculate height and apply with JavaScript.
  • Assign the value to an inline style or a CSS variable that overrides the default.

5. Use CSS Fallbacks (via Custom Code)

  • Set fallback styles in the Head section of Page Settings:
  • Use CSS feature queries like @supports not (height: 100vh) to assign alternate styles.
  • While Webflow doesn't support full CSS feature queries natively, you can inject them through <style> in custom code.

6. Use Webflow’s Embed Element for Targeted Fixes

  • Add a custom <style> or <script> inside an Embed element to override styles on specific elements.
  • Target Safari 5.1 using a UA sniff (not ideal, but usable for an outdated browser):
  • Use JavaScript to detect older Safari versions and add a class to the <body> tag, then target that in your CSS.

Summary

To work around vh and vw issues in Safari 5.1 in Webflow, replace viewport units with % or px, use JavaScript to dynamically set heights, and inject custom fallback styles using Webflow embeds or page settings. This ensures basic layout compatibility in older versions of Safari.

Rate this answer

Other Webflow Questions