You build a full-screen hero section with height: 100vh. It looks perfect in desktop Chrome and in the responsive mode of DevTools. Then you open it on a real phone and the bottom of the section, maybe your call-to-action button, is hidden under the browser’s toolbar. This is the famous 100vh problem, and it has confused developers for more than a decade. The good news is that CSS now has proper tools to solve it.
This guide explains why 100vh misbehaves on mobile, what the newer viewport units mean, which one to use in common layouts and how to handle the on-screen keyboard and notches.
What viewport units are
Viewport units are lengths relative to the browser window’s size. 1vh is one percent of the viewport height and 1vw is one percent of its width. vmin and vmax refer to the smaller and larger of the two. They are handy for full-screen sections, fluid typography and spacing that scales with the screen.
Why 100vh breaks on phones
On desktop, the viewport is fixed while you browse. On phones, the browser’s address bar and toolbar slide away as you scroll down and return as you scroll up, so the visible area keeps changing. Mobile browsers chose to define 100vh as the tallest possible viewport, the one with the toolbars hidden. When the toolbars are showing, which is how every page starts, the real visible height is smaller, so a 100vh element is taller than the screen and its bottom is cut off.
Browsers did this deliberately to avoid the page layout jumping every time the toolbar moved. But it left developers with no unit for “the height I can see right now” until the newer units arrived.
The newer units: svh, lvh and dvh
| Unit | Meaning | When toolbars are showing |
|---|---|---|
svh | Small viewport height: the smallest the viewport gets, with toolbars visible | Fits exactly, with extra space when toolbars hide |
lvh | Large viewport height: the biggest it gets, with toolbars hidden | Taller than visible, the same as the old 100vh behaviour |
dvh | Dynamic viewport height: tracks the current visible height | Fits exactly, and updates as the toolbar moves |
The same family exists for width and for the smaller and larger axes: svw, lvw, dvw, svmin, dvmax and so on. On desktop, where toolbars do not slide away, all three variants are the same size. These units are supported in current versions of the major browsers, having arrived between about 2022 and 2023, but check a support table such as MDN or Can I use for your audience, especially for older Android WebViews.
The recommended pattern: modern unit with a fallback
Browsers ignore declarations they do not understand, so list the old value first and the modern value after it. Older browsers use the first, modern ones override with the second.
.hero {
min-height: 100vh; /* fallback for older browsers */
min-height: 100svh; /* never taller than the screen when the toolbar shows */
}
/* If you want it to follow the toolbar as it moves */
.app-shell {
height: 100vh;
height: 100dvh;
}Use min-height instead of height for content sections. A fixed height with lots of content can overflow on small or landscape screens, while min-height lets the section grow when it needs to.
Which unit for which layout?
- Hero or landing sections:
min-height: 100svh. It always fits the first screen and does not jump when the toolbar hides. - App-like layouts with a fixed header and footer (chat screens, dashboards):
height: 100dvhso the layout fills what is visible, with an internal scrolling area. - Full-bleed backgrounds that should cover everything:
lvhso no gap shows when the toolbar retracts. - Modals and drawers:
max-height: 100dvhor90dvh, with an internal scroll area.
Be aware that dvh can cause layout recalculation as the toolbar moves. For long scrolling pages, svh is usually calmer. Reserve dvh for layouts where exact fit matters.
A JavaScript fallback for old browsers
If you must support browsers that lack the new units, set a custom property from the real inner height and use it with a fallback.
function setVh() {
document.documentElement.style.setProperty(
'--vh', window.innerHeight * 0.01 + 'px'
);
}
setVh();
window.addEventListener('resize', setVh);
/* CSS */
.hero {
min-height: 100vh;
min-height: calc(var(--vh, 1vh) * 100);
}Debounce the resize handler if you attach it to anything heavier than this, and remove the fallback when your supported browsers all handle svh and dvh.
The 100vw trap on desktop
A related bug affects width. 100vw includes the vertical scrollbar, so on desktop browsers that show a classic scrollbar a width: 100vw element is wider than the visible page and triggers a horizontal scrollbar. For full-width blocks use width: 100% or let a block-level element fill the container naturally. Reserve vw for things like fluid type and spacing, not for sizing the element that spans the page.
The on-screen keyboard
When the keyboard opens, behaviour differs between platforms. In many mobile browsers, the layout viewport does not change, so vh and even dvh may not shrink, and a fixed bottom button can end up hidden behind the keyboard. There are two ways to deal with it.
- The
interactive-widgetviewport option. Add it to the viewport meta tag, for example<meta name="viewport" content="width=device-width, initial-scale=1, interactive-widget=resizes-content">. Chromium-based Android browsers support it and let you choose whether the keyboard resizes the layout, only the visual viewport, or overlays the content. Support elsewhere is not guaranteed, so test it. - The Visual Viewport API.
window.visualViewportreports the part of the page actually visible, including when the keyboard or pinch-zoom changes it. Listen to itsresizeevent to reposition floating bars.
Always test forms and chat inputs on a real device with the keyboard open, since emulators do not reproduce this accurately.
Notches and safe areas
Modern phones have rounded corners, camera cutouts and gesture bars that overlap the page edges. If you use viewport-fit=cover to draw under them, protect your controls with the safe-area insets.
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
.bottom-bar {
position: fixed;
inset-inline: 0;
bottom: 0;
padding-bottom: env(safe-area-inset-bottom, 0px);
}Fluid type with viewport units, safely
Sizing text purely with vw breaks zooming: text will not scale when users increase the browser’s zoom or font size, which is an accessibility problem. Combine a relative unit with a viewport term inside clamp() so that zoom still works and the size stays within sensible limits.
h1 { font-size: clamp(1.75rem, 1.2rem + 2.5vw, 3rem); }Common mistakes
- Using
height: 100vhfor content sections and clipping text on small or landscape screens. Usemin-height. - Testing only in desktop DevTools, which does not simulate the retracting toolbar.
- Using
dvheverywhere and causing jank on long pages. - Using
100vwfor page-wide blocks. - Fixed bottom bars that ignore the keyboard and the safe-area inset.
- Fluid text sized purely in
vw.
Testing checklist
- Open the page on a real phone in the browser with its toolbar visible, then scroll to hide it, and confirm nothing is cut off.
- Rotate to landscape and check that content is reachable.
- Focus an input and open the keyboard to check fixed elements.
- Zoom text to 200% and confirm nothing overlaps.
- Try at least one older Android device and one iPhone.
To quickly view a page at phone, tablet and desktop widths on your own phone while you work, the free Dev Browser app can help; see the Dev Browser guide. Layout shifts from changing heights also affect Core Web Vitals, covered in fixing LCP, INP and CLS on mobile. Related reading: CSS breakpoints, media queries and container queries, debugging JavaScript console errors on mobile, mobile-first indexing and the responsive web design testing checklist. See more on the products page.
Frequently asked questions
Should I replace every vh with dvh?
No. Use svh for sections that should fit the first screen, dvh where exact live fit matters, and keep a vh fallback for older browsers.
Why does 100vh work in DevTools but not on my phone?
DevTools emulation does not model the browser toolbars that appear and disappear on real phones, so the problem only shows on a real device.
Does 100% height work instead?
Percentage heights depend on the parent having a defined height, so you must set height: 100% on html, body and every wrapper in between. Modern viewport units are simpler.
Are the new units safe to use now?
They are supported in current mainstream browsers. With a vh fallback declared first, older browsers still get a reasonable layout.
Disclaimer: Browser behaviour and support change with each release. Verify features against current documentation such as MDN and test on real devices before shipping to production.