๐Ÿ“ฑ Dynamic Viewport Units โ€” dvh & dvw Explained

๐ŸŒ 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.

>>โ€œdvh gives you the REAL height of the usable screen โ€” no more mobile layout jumps.โ€

Note

โœ” Supported in all modern browsers
โœ” 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

๐Ÿ”ฅ dvh always uses the current viewport height. ๐Ÿ”ฅ dvw uses the current viewport width.

๐Ÿ“ The 3 Types of Viewport Units (Modern)

UnitDescription
lvhLargest viewport height
svhSmallest viewport height
dvhDynamic 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

Propertyvhdvh
Mobile address bar affects layout?โœ… YesโŒ No
Stable full-screen height?โŒ Noโœ… Yes
Responsive to dynamic UI changes?โŒ Noโœ… Yes

Note

๐Ÿ’ก Always prefer dvh over vh for mobile screens.

๐ŸŽจ 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

โœ” If supporting iOS Safari โ†’ dvh gives perfect results compared to vh. โœ” Combine dvh + safe-area insets for notch devices.

๐Ÿ”ฅ 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.

>>โ€œSay goodbye to the 100vh mobile bug โ€” dvh is the future of mobile CSS.โ€

Learn more โ†’MDN Docs ๐Ÿ“˜