What Are Modern Viewport Units?
Traditional viewport units (vh, vw) have long struggled on mobile browsers due to dynamic UI bars (address bar, navigation bar) appearing and disappearing. Modern CSS introduces new units to fix these issues and give developersprecise, reliable viewport measurements.
Note
β Essential for mobile-first, fullscreen layouts
β Works together with dvh/dvw
π¦ The 4 Modern Viewport Units
| Unit | Meaning | Represents |
|---|---|---|
| svh | Small Viewport Height | Height when browser UI is fully visible (smallest possible) |
| svw | Small Viewport Width | Width when UI reduces viewport (rare) |
| lvh | Large Viewport Height | Height when browser UI is fully hidden (largest possible) |
| lvw | Large Viewport Width | Widest possible width |
Note
π₯ lvh = largest height
π₯ dvh = dynamic, updating height
π Syntax
Syntax
height: 100svh; /* Small viewport height */
height: 100lvh; /* Large viewport height */
width: 100svw; /* Small viewport width */
width: 100lvw; /* Large viewport width */π§ Why Do We Need These Units?
Mobile browser UI bars appear/disappear when scrolling. This causes the traditional 100vh unit to:
- Make content jump suddenly
- Cut off bottom sections
- Show blank space at the bottom
- Create unpredictable layouts
π Understanding Each Unit
1οΈβ£ svh β Small Viewport Height
Represents the minimum height of the viewport (when the browser UI is fully visible).
svh Example
.safe-section {
height: 100svh;
}Useful when you want to avoid layout shifting on scroll.
2οΈβ£ lvh β Large Viewport Height
Represents the maximum height the viewport can reach (when browser UI collapses).
lvh Example
.fullscreen {
height: 100lvh;
}Perfect for true fullscreen on mobile apps.
3οΈβ£ svw β Small Viewport Width
Smallest width visible (rarely changes except with side UI panels).
svw Example
.sidebar {
width: 20svw;
}4οΈβ£ lvw β Large Viewport Width
Largest possible viewport width β useful for responsive hero designs.
lvw Example
.wide-banner {
width: 100lvw;
}π§ͺ Practical Examples
π± 1. Stable Mobile Hero Section
Stable Hero
.hero {
height: 100svh; /* Prevent jumpiness */
background: url(hero.jpg) center/cover;
}π 2. True Fullscreen Mode
Full Screen
.hero-expanding {
height: 100lvh; /* Tallest height available */
}π 3. Dynamic App Layout (best UX)
Dynamically Adjusting Layout
.page {
min-height: 100dvh; /* Updates as UI changes */
}Combine with svh & lvh for best control.
π― 4. Responsive Typography Using vmin and vmax
Typography
.title {
font-size: 5vmin;
}Works well with modern viewport units to scale proportions.
𧬠How These Units Work Together
| Scenario | svh | lvh | dvh |
|---|---|---|---|
| Browser UI visible | β Accurate | β Too large | β Accurate |
| Browser UI hidden | β Too small | β Accurate | β Accurate |
| UI changing during scroll | β Static | β Static | β Updates live |
Note
π‘ Use svh or lvh when you want stability.
β οΈ Common Mistakes
- β Still using 100vh for mobile layouts
- β Assuming svh updates on scroll (it doesnβt)
- β Using lvh in components that shouldnβt jump on scroll
- β Not testing on different mobile browsers
Note
Use dvh when you want dynamic behavior,
Use svh or lvh when you want stability.
π₯ Summary
Modern viewport units (svh, svw, lvh, lvw) finally solve the classic mobile viewport bug by providing stable and predictable sizing. Combined with dvh/dvw, they give designers full control over fullscreen layouts on mobile browsers.
Learn more βMDN Docs π