Container-relative units measure sizes against the nearest query container, rather than the viewport. They let components scale with the space they occupy and pair naturally with container queries. section 4.1.3 section 4.1.6
Choose the unit that matches the container axis:
- Use cqw and cqh for widths and heights; use cqi and cqb for inline and block dimensions. section 4.1.6
- Use these units when component sizing should follow its container rather than the viewport. section 4.1.6
Table 4.1 The most useful modern CSS units
| Category | Unit | Relative to | Recommended use |
Dynamic viewport |
|
1% of the current viewport, adjusting as the browser chrome appears or disappears |
Full-height sections that must not jump on mobile when the address bar shows or hides |
|
1% of the small viewport (chrome fully expanded, smallest area) |
Guaranteeing content still fits when the browser UI takes the most space |
|
|
1% of the large viewport (chrome fully retracted, largest area) |
Sizing against the maximum available area |
|
Logical viewport |
|
1% of the viewport along the inline / block axis |
Viewport-based sizing that follows the writing mode automatically |
Container |
|
1% of the nearest query container’s inline / block size |
Components that scale to their container rather than the viewport, paired with container queries |
|
1% of the query container’s width / height |
Physical container sizing when the axis is fixed regardless of writing mode |
|
Text-relative |
|
The line height of the element / root element |
Vertical rhythm: margins and spacing that align to the baseline grid |
|
The cap height of the current font (height of capital letters) |
Headings and display type sized to the actual letter shapes |
|
|
The advance width of the |
Line lengths, inputs, and columns measured in characters |
|
|
The advance width of the CJK water ideograph (水) |
Consistent sizing for ideographic scripts |
Compare container units with other modern CSS unit families and their relative sizing bases. section 4.1.6
