CSS Viewport Units
CSS
What are Viewport Units?
Viewport units are relative units in CSS that are based on the size of the browser window (viewport).
Viewport Units
Unit | Meaning | Based on… |
---|---|---|
vw | Viewport Width | 1vw = 1% of browser width |
vh | Viewport Height | 1vh = 1% of browser height |
vmin | Minimum of vw or vh | Smaller side of viewport |
vmax | Maximum of vw or vh | Larger side of viewport |
1. vw (Viewport Width)
The text size increases or decreases with screen width.
2. vh (Viewport Height)
Common for full-screen sections like banners.
3. vmin and vmax
Useful when you want elements to scale uniformly on all devices.
Examples
Fullscreen Section
Responsive Font
Unit | Description |
---|---|
vw | 1% of the viewport width |
vh | 1% of the viewport height |
vmin | 1% of the smaller side |
vmax | 1% of the larger side |