gotchacssMajor
100vh causes overflow on mobile due to browser chrome
Viewed 1 times
100vhmobile viewportdvhsvhbrowser chromeviewport units
mobileios safarichrome android
Problem
An element set to height: 100vh extends beyond the visible screen on mobile browsers. The URL bar and bottom navigation bar are not accounted for, causing a scroll or cutoff.
Solution
Use the dynamic viewport unit dvh (dynamic viewport height), or the svh/lvh variants depending on the desired behavior:
/* Modern approach: dvh adjusts as browser chrome appears/disappears */
.hero {
height: 100dvh;
}
/* svh = small viewport (browser chrome visible) */
.section {
min-height: 100svh;
}
/* Fallback for older browsers */
.hero {
height: 100vh; /* fallback */
height: 100dvh; /* override for supporting browsers */
}Why
On mobile browsers, the viewport height (100vh) is calculated based on the maximum viewport size — i.e., without the browser chrome. When the URL bar is visible, the actual visible area is smaller, so 100vh overflows.
Gotchas
- dvh, svh, and lvh have broad support as of 2023 but check caniuse for your target browsers.
- On desktop, 100vh and 100dvh are equivalent since there is no dynamic chrome.
- Using 100svh gives the most conservative (always-fits) measurement, useful for fixed full-screen layouts.
Context
Full-screen sections or hero components that overflow on mobile browsers.
Revisions (0)
No revisions yet.