Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Units and Values

The dvh, svh and lvh units

Reference for the CSS dynamic, small and large viewport units dvh, svh and lvh: fixing full-height layouts on mobile where browser toolbars appear and hide.

Mobile browsers show toolbars, such as the address bar, that slide away as you scroll. That means the visible area has two sizes: a small one when the toolbars are shown and a large one when they are hidden. The classic vh unit uses the large size, so 100vh can be taller than what you can actually see on first load.

Three newer families solve this. svh always uses the small viewport, lvh always uses the large viewport, and dvh uses the dynamic viewport, which follows the toolbars as they appear and disappear. The same three prefixes exist for width (svw, lvw, dvw), for min and max (dvmin, svmax, ...) and for logical axes (dvi, dvb, ...).

CSS
.screen {
  min-height: 100vh;   /* fallback */
  min-height: 100dvh;  /* mobile-aware */
}

Try it

Measuring the three heights

On a phone, with the toolbars shown, svh is the smallest and lvh and vh are the largest; dvh matches whichever state the toolbars are in at that moment.

Syntax

CSS
<length> = <number>svh | <number>lvh | <number>dvh
         | <number>svw | <number>lvw | <number>dvw
         | <number>svmin | <number>svmax | <number>lvmin | <number>lvmax
         | <number>dvmin | <number>dvmax
         | <number>svi | <number>svb | <number>lvi | <number>lvb | <number>dvi | <number>dvb
  • Applies to: any property that accepts a <length>.
  • Animatable: yes, as part of a length.
  • On desktop: all three are equal to each other and to vh, because desktop browsers have no collapsing toolbars.

Values

Value Description
svh 1% of the small viewport height: toolbars visible.
lvh 1% of the large viewport height: toolbars hidden. Same as classic vh.
dvh 1% of the dynamic viewport height: follows the toolbars as they move.
svw, lvw, dvw The same idea for width (rarely different).
dvmin, dvmax, svmin, ... Smaller or larger of the two dimensions.

Usage notes

  • Pick svh for "always fits". A hero section of 100svh never hides its content behind the toolbar.
  • Pick dvh for "fills exactly". It always matches the visible area, but the layout may be recalculated as the user scrolls, so avoid it on elements with expensive layout or content that could jump.
  • Pick lvh for backgrounds. A decorative background can use the large size so it never leaves a gap when toolbars hide.
  • Provide a fallback. Write 100vh first and 100dvh after; browsers that do not understand the second declaration keep the first.
  • Test on a real device. Desktop browser device emulation does not show toolbar collapsing.
  • Keyboard. On some mobile browsers the on-screen keyboard changes the dynamic viewport and on others it does not; do not depend on it.

Browser support

Supported in current versions of the major browsers. Check a compatibility table if you must support older mobile browsers, and keep a vh fallback.