← Tous les articles

CSS: 100vh too tall on mobile, the dvh fix

Your full-screen section overflows on iPhone and Android? The address bar skews 100vh. dvh, svh and lvh units solve it.

CSS: 100vh too tall on mobile, the dvh fix

Key points

  • On mobile, 100vh equals the screen without the address bar.
  • 100dvh follows the height that is actually visible.
  • Keep 100vh as a fallback for older browsers.

A full-screen header that is perfect on desktop, but whose button hides under the browser bar on mobile: one of the issues we fix most often in audits.

Why 100vh is not the screen

On mobile, the address bar hides as you scroll. To stop pages jumping, browsers set 100vh to the largest height, bar hidden. When the bar shows, the element overflows.

The new units

  • svh (small): height with bars showing, the smallest.
  • lvh (large): height with bars hidden, like the old 100vh.
  • dvh (dynamic): follows what is visible in real time.

The code we use

.hero {
  min-height: 100vh;   /* fallback */
  min-height: 100svh;  /* never hidden by the bar */
}

For large sections we usually prefer svh over dvh: dvh changes while scrolling and can shift the layout. dvh is ideal for fixed elements such as a full-screen mobile menu or a modal.

Use min-height, not height

With height, longer text overflows the section, especially on small screens or with larger fonts. min-height lets the section grow.

FAQ

Do I still need the JavaScript –vh trick?

No, current browsers support dvh/svh. Just keep 100vh as a fallback.

Is there a width equivalent?

Yes (dvw, svw), but width is rarely the problem.

Facing this on your site or app? We diagnose and fix it.

Partager LinkedIn Facebook X WhatsApp
</>

webtestudio

Agence web : sites WordPress sur mesure, thèmes premium et logiciels SaaS.

Parler de votre projet →