๐ What Are Dynamic Viewport Units?
dvh and dvw are modern CSS viewport units that fix one of the biggest problems with traditional vh and vw โ especially on mobile devices. They provide a stable, accurate measurement of the viewport size, even when browser UI elements (like address bars) expand or collapse.
Note
โ Designed for mobile UX
โ Prevents layout shifting caused by browser chrome
๐ฆ Why Do We Need dvh & dvw?
Mobile browsers change viewport height as you scroll:
- Address bar hides โ viewport height increases
- Address bar shows โ viewport height decreases
Traditional 100vh is calculated using the largest possible height, which causes:
- Content jumping up/down
- Bottom elements becoming unreachable
- Incorrect full-screen sections
Note
๐ The 3 Types of Viewport Units (Modern)
| Unit | Description |
|---|---|
| lvh | Largest viewport height |
| svh | Smallest viewport height |
| dvh | Dynamic height (changes as browser chrome moves) |
Same applies to width units: lvw, svw, dvw.
๐ Syntax
Syntax
height: 100dvh;
width: 100dvw;๐งช Example 1 โ Perfect Full-Screen Section
Full Screen
.hero {
height: 100dvh;
background: url(hero.jpg) center/cover;
}The hero section always fits the visible screen โ no unexpected gaps.
๐งช Example 2 โ Mobile Bottom Navigation
Bottom Nav
.bottom-nav {
position: fixed;
bottom: 0;
height: 10dvh;
width: 100dvw;
background: #111;
}The bottom navigation bar stays aligned even when browser UI changes height.
๐งช Example 3 โ Prevent Scroll Jumping
Scroll-safe Full Screen Component
.page {
min-height: 100dvh;
}Eliminates sudden resizing when the mobile address bar collapses.
๐ฑ Example 4 โ Responsive Sidebar Using dvw
Sidebar Example
.sidebar {
width: 30dvw;
height: 100dvh;
background: #222;
}๐ง dvh vs vh โ Key Differences
| Property | vh | dvh |
|---|---|---|
| Mobile address bar affects layout? | โ Yes | โ No |
| Stable full-screen height? | โ No | โ Yes |
| Responsive to dynamic UI changes? | โ No | โ Yes |
Note
๐จ dvh for Smooth Mobile Layouts
dvh is especially useful for:
- Hero sections
- Modals
- Sidebars
- Full-screen image sliders
- Bottom sheets
- Chat apps
โ ๏ธ Common Mistakes
- โ Still using 100vh for mobile designs (creates jumpy layouts)
- โ Assuming dvh works the same as vh (it updates dynamically)
- โ Not testing on actual mobile browsers
Note
๐ฅ Summary
dvh and dvw are modern, reliable viewport units that eliminate the classic mobile viewport bug caused by the browser UI bar. They enable truly stable full-screen layouts and provide better responsiveness across all mobile browsers.
Learn more โMDN Docs ๐