Viewport-percentage units are 1% of the initial containing block, which on screen is the viewport. Mobile browsers complicate that: the address bar and toolbar retract as you scroll down and expand when you scroll back. CSS Values 4 defines three viewport sizes for this:
- Large viewport (
lvh,lvw, …): sized as if every retractable UI is retracted. Fixed, so it never causes relayout, but content can be hidden behind the toolbar when it's showing. - Small viewport (
svh, …): sized as if the UI is expanded. Fixed too;100svhalways fits, but leaves a gap once the toolbar hides. - Dynamic viewport (
dvh, …): the current size, between the two. Exact, but it changes while the user scrolls, which can resize content mid-scroll and costs layout work. Browsers may hold the value during the toolbar animation instead of updating every frame.
The original vh/vw (now the "default" units) are defined as the large viewport. That's why height: 100vh heroes on phones had their bottom covered by the toolbar.
Each comes in w, h, i (inline axis), b (block axis), min and max variants: svi, dvmax, and so on. The new prefixes shipped in Chrome 108, Firefox 101 and Safari 15.4.
What doesn't count:
- On-screen keyboards usually overlay the page and change none of these units.
- Scrollbars: viewport units are sized as if there were no scrollbar, unless the root's
overflow(for exampleoverflow: scroll) orscrollbar-gutterreserves space unconditionally.
Rule of thumb: min-height: 100svh for a hero that must fit on load, 100dvh for a full-screen app shell where tracking the toolbar matters, lvh for backgrounds that should never show a gap.