Explore how modern CSS viewport units like lvh, svh, and dvh provide reliable solutions for mobile layouts, replacing the broken 100vh trick. Learn key distinctions, practical uses, and limitations for responsive design.
Why does using 100vh for a full-screen hero section on mobile often result in content being hidden behind the address bar?
Explanation: 100vh is measured as if browser UI (such as the address bar) is retracted, not accounting for their actual presence, which hides content below them. It's not determined by overall screen size, does not include scrollbars specifically, and does not depend on JavaScript.
Which scenario is best suited for using large viewport units (lvh, lvw) in a layout?
Explanation: Large viewport units represent the size with all browser chrome retracted, ideal for fullscreen overlays like modals. Sticky bars need guaranteed visibility, best with sv units. Scroll animations can jitter with dynamic units, and sidebars are unrelated to viewport chrome.
What is a key characteristic of small viewport units (svh, svw) in CSS?
Explanation: sv units ensure content stays visible even when browser UI is expanded, perfectly suiting persistent elements like headers. They do not shrink with scroll, do not match lvh (which is bigger), and do not cause layout shifts.
How do dynamic viewport units (dvh, dvw) behave when the mobile browser's address bar appears and disappears?
Explanation: Dynamic units update as the browser UI slides in or out, providing an up-to-date match with visible screen space. lvh is always at maximum size, svh stays at minimum, and no JavaScript is needed for dvh/dvw updates.
Why was the old JavaScript workaround for mobile viewport sizing considered a 'band-aid' solution?
Explanation: The JavaScript hack caused unwanted visual shifts and required early script execution, making it unreliable. It was not faster than CSS, didn't work exclusively in Chrome, and didn't ensure perfect sizing.
If you want a bottom cookie consent banner to always remain visible above any browser UI, which CSS unit family should you choose?
Explanation: svh units guarantee the banner remains above any UI such as toolbars or address bars. lvh could be hidden under browser UI, dvh updates but may not always offer guaranteed visibility, and vh is unreliable on mobile.
Why should you avoid tying scroll animations directly to dvh changes?
Explanation: Browsers intentionally smooth dvh changes to avoid jitter, so real-time animations tied to it can appear laggy. dvh units are not deprecated, do not hide content on desktop, and do update with address bar changes.
What happens if you set a fullscreen modal's height to 100lvh on mobile?
Explanation: 100lvh expands to the largest viewport possible, completely covering the screen when UI is hidden. It does not guarantee visibility above UI, does not resize with every scroll, and works on mobile, not just desktop.
Which CSS unit would you use to size a hero section so all content is visible when a mobile page first loads, with nothing hidden below the fold?
Explanation: svh ensures the hero section fits entirely within the space not obscured by browser UI at page load. lvh may hide elements under the chrome, 100vh suffers from old mobile limitations, and dvh could expand beyond the visible area as the UI retracts.
What do the new lvh, svh, and dvh units allow web developers to do?
Explanation: These units let developers confidently design for maximum, minimum, or dynamic viewport sizes, solving long-standing layout problems. They do not crop images, are not about JavaScript, and do not control color themes.