Performance: Viewport units
Viewport units affect the layout and sizing of elements relative to the browser window size, impacting rendering and layout recalculations on resize.
Jump into concepts and practice - no test required
div { height: 100dvh; } /* dynamic viewport height */div { height: 100vh; } /* full viewport height */| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using 100vh for height | Minimal | Multiple on resize | Medium | [X] Bad |
| Using 100dvh for height | Minimal | Single or none on resize | Low | [OK] Good |
1vw represent?vw stands for viewport width, so 1vw equals 1% of the browser window's width.vh which is viewport height, vw relates only to width, not height or pixels.1vw = 1% viewport width [OK]vh means viewport height, so 50vh means 50% of the viewport height.vw is viewport width, vmin is the smaller of width or height, and vmax is the larger. Only vh sets height relative to viewport height directly.div {
width: 10vw;
height: 20vh;
}.box {
width: 50vmin;
height: 50vmin;
}vmin behaviorvmin uses the smaller of viewport width or height. If viewport changes size (like resizing window), the box size changes too.vmin depends on viewport size changes [OK]vmin is the smaller of viewport width or height, vmax is the larger.vmin so the square fits the smaller dimension.