CSS Units svh, lvh, and dvh Replace JavaScript Hacks for Mobile Viewport Fixes
For years, developers used a JavaScript workaround to fix the '100vh bug' on mobile browsers, where full-screen sections appeared taller than the actual visible area due to browser UI elements like address bars. The root cause is that 100vh measures the browser's largest possible viewport, not the current visible height, causing content like CTA buttons to be hidden behind toolbars on page load. iOS Safari and Chrome on Android historically handled the unit differently, making the bug inconsistent and hard to reproduce. Since 2022, all major browser engines support three new CSS viewport units — svh, lvh, and dvh — which precisely measure the small, large, and dynamic viewport heights respectively. Developers can now replace the JavaScript resize-listener hack with a single CSS declaration using dvh or svh, eliminating layout jumps and reducing code complexity.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in