Academy / Advanced Level: HTML and CSS
Advanced Responsive Web Design Techniques
Viewport Units (vw, vh, vmin, vmax)
Viewport units are powerful tools for building responsive layouts that dynamically adjust based on the size of the viewport (the visible part of the browser window). They are particularly useful for creating fluid layouts and typography.
Viewport Units:
vw: 1% of the viewport width.vh: 1% of the viewport height.vmin: 1% of the smaller dimension (width or height).vmax: 1% of the larger dimension (width or height).
Example: Responsive Typography with vw
h1 {
font-size: 5vw; /* The font size will be 5% of the viewport width */
}
In this example, the h1 element will dynamically adjust its font size based on the width of the viewport. This ensures that the text looks great on screens of all sizes.