Dynamic viewport units are CSS length units, most commonly dvh and dvw, that measure the currently visible viewport and update when mobile browser interface elements such as the address bar expand or retract. On the Mobile web, they solve the long-standing problem that 100vh often produces a block taller than the visible screen, hiding buttons and footers behind browser chrome.
The units belong to a family of viewport-percentage lengths defined in CSS Values and Units Module Level 4, alongside the small (svh) and large (lvh) variants. Choosing correctly among them is a routine decision in mobile-first design and in building full-screen layouts for progressive web apps.
Why mobile browsers needed dynamic viewport units
Mobile browsers resize their visible area during scrolling. When a user scrolls down, the address bar and sometimes the bottom toolbar collapse to give content more room; when the user scrolls up or taps the top, they reappear. The viewport height therefore changes by roughly 50 to 120 CSS pixels depending on the browser, device and orientation.
Early implementations faced a dilemma. Recomputing vh on every toolbar movement would force constant layout recalculation and visible jumps, so browsers fixed 1vh to 1% of the largest possible viewport, the one with toolbars retracted. A hero section set to height: 100vh thus overflowed the screen whenever the toolbars were visible, which is exactly the state in which a page first loads.
The CSS Working Group responded by defining three explicit viewport sizes instead of one ambiguous value. Developers can now state whether a length should follow the smallest, the largest or the current viewport, and browsers implemented all three between 2022 and early 2023 in Safari, Firefox and Chromium-based browsers.
The dvh family and the other viewport unit variants
Each viewport size comes with six units: height, width, inline, block, min and max. The dynamic set uses the dv prefix, so dvh, dvw, dvi, dvb, dvmin and dvmax each equal 1% of the dynamic viewport in the corresponding dimension.
The table below compares the three viewport sizes that underlie the unit families.
| Unit family | Measured viewport | Toolbar state assumed | Changes during scrolling |
|---|---|---|---|
| Small (svh, svw) | Smallest possible viewport | All dynamic toolbars expanded | No |
| Large (lvh, lvw) | Largest possible viewport | All dynamic toolbars retracted | No |
| Dynamic (dvh, dvw) | Current viewport | Actual state at this moment | Yes |
| Default (vh, vw) | Browser-defined, usually large | Usually toolbars retracted | No in most mobile browsers |
The logical units dvi and dvb follow the writing mode of the element, so dvb corresponds to height in horizontal text and to width in vertical writing modes. The dvmin and dvmax units pick the smaller or larger dimension, which is useful for elements that must fit in both portrait and landscape orientation.
How dynamic viewport units behave in practice
A value in dvh is recomputed when the toolbars settle into a new state. Browsers do not necessarily update it on every animation frame; many apply the new value once the toolbar transition ends to limit layout thrashing, so an element can briefly appear too tall or too short during the animation.
The on-screen keyboard is a separate matter. By default, mobile browsers treat the keyboard as resizing only the visual viewport, which leaves the layout viewport and all viewport units unchanged. The interactive-widget key in the viewport meta tag can change this: the value resizes-content makes the layout viewport, and with it the dvh value, shrink when the keyboard opens, while overlays-content leaves everything unchanged.
The following table shows which interface events influence each unit.
| Event | Default and large units | Small units | Dynamic units |
|---|---|---|---|
| Toolbar retracts on scroll | Unchanged | Unchanged | Increases |
| Toolbar reappears | Unchanged | Unchanged | Decreases |
| Device rotation | Recomputed | Recomputed | Recomputed |
| Virtual keyboard opens (default) | Unchanged | Unchanged | Unchanged |
| Keyboard with resizes-content | Recomputed | Recomputed | Recomputed |
| Pinch to zoom | Unchanged | Unchanged | Unchanged |
Choosing between dvh, svh and lvh
The right unit depends on whether the element must always fit fully on screen or should simply fill the space that is available. Small viewport units are the safest default for content that must remain visible, while dynamic units suit elements that should follow the screen exactly.
| Situation | Recommended unit | Reason |
|---|---|---|
| Landing hero with call to action | svh | Button stays visible on first load |
| Full-screen app shell or PWA | dvh | Fills the screen in every toolbar state |
| Modal or bottom sheet height limit | dvh with max-height | Never extends behind toolbars |
| Decorative background section | lvh | Avoids resizing and repainting |
| Long scrolling content | No viewport unit | Content height should drive layout |
For older browsers, a progressive fallback is standard practice: declare height: 100vh first and height: 100dvh on the next line, so engines that do not understand the new unit keep the old value. Combining the unit with env(safe-area-inset-bottom) padding keeps controls clear of rounded corners and home indicators on notched devices.
Limitations and common mistakes
Dynamic units are not free in terms of performance. Every change of the dynamic viewport can trigger layout of all elements sized in dvh, and large pages that use the unit widely may show scroll jank on low-end phones.
- Using dvh for everything causes content to jump as the user scrolls; reserve it for elements that genuinely need to track the screen.
- Expecting dvh to react to the keyboard leads to hidden input fields; the default behavior does not include the keyboard unless
interactive-widgetis set. - Replacing vh without a fallback breaks layouts in older in-app browsers and embedded web views that lack support.
- Relying on JavaScript resize listeners instead of the CSS units adds complexity and often reproduces the same flicker the units were designed to avoid.
Desktop browsers have no retractable toolbars, so there the dynamic, small and large values are normally identical. Testing therefore has to happen on real mobile devices or accurate emulators, because desktop previews hide the difference completely.
In everyday language
On a phone, the browser’s address bar slides away when you scroll and comes back when you scroll up. That means the usable screen keeps growing and shrinking a little.
Dynamic viewport units let a web page measure the screen as it really is right now. A full-screen panel built with them always fits exactly, like a window blind that adjusts itself whenever the window frame changes size.
Seen in the real world
A regional food delivery service builds its ordering flow as a progressive web app. Testers on mid-range Android phones and iPhones report that the Place order button sits behind the browser toolbar on the checkout screen, because the layout uses height: 100vh and the page is taller than the visible area by about 80 pixels.
The front-end team changes the checkout container to min-height: 100vh followed by min-height: 100dvh, adds bottom padding with env(safe-area-inset-bottom) and sets the hero image on the start page to svh so it never pushes content off screen. After release, the button is fully visible in every toolbar state, and the share of users who abandon the flow at the checkout step drops noticeably in the following weeks.