cqw
One percent of the nearest query container's width.
Safe to useBaseline: widely available
| Browser | Since |
|---|---|
| Chrome | 105+ |
| Chrome Android | 105+ |
| Edge | 105+ |
| Firefox | 110+ |
| Firefox Android | 110+ |
| Safari | 16+ |
| Safari iOS | 16+ |
Formula 1cqw = 1/100 of the nearest container's width
How it works
1cqw is a hundredth of the width of whichever ancestor is the nearest query container. Giving an element container-type: inline-size makes it one, and descendants can then size themselves from it. A card whose heading is font-size: clamp(1.25rem, 6cqw, 3rem) adapts to the slot it was placed in and ignores the window, which is the reason the unit exists: in a container 400px wide the heading is 24px, in one 1000px wide it stops at 48px, and the size of the window changes neither.
The width is that of the container’s content box. A container 400px wide with 50px of padding on each side (box-sizing: border-box) offers 300px, so 100cqw inside it is 300px, not 400px. Padding is not counted, and a card that looks 400px wide to the eye measures less.
With no query container among its ancestors, the unit reads the small viewport: in a 1280px window, 10cqw with no container-type above it came to 128px, the same as 10svw. The console says nothing and the card still renders, so the symptom is a component that follows the window instead of its slot. A second container in between gives wrong numbers of another kind: the nearest ancestor with container-type answers, whether or not it is the one you had in mind, and an ancestor without the property is passed over.
Try it
A container you can resize
Drag the sliders. The box is a real query container, and the readings are 10 of each container unit measured inside it.
- Container, measured
- 300 × 140px
10cqw- 30px
10cqh- 14px
10cqi- 30px
10cqb- 14px
10cqmin- 14px
10cqmax- 30px
The same as a table
| Unit | 300 × 140px | 500 × 140px |
|---|---|---|
10cqw | 30px | 50px |
10cqh | 14px | 14px |
10cqi | 30px | 50px |
10cqb | 14px | 14px |
10cqmin | 14px | 14px |
10cqmax | 30px | 50px |
What changes it
- Moves with
- page zoom
- the query container
- Stays put under
- the reader's text size
- the window size
- the font in use
- phone toolbars
- the writing mode
Reach for it when
Components dropped into slots of different widths: sidebars, grids, dialogs.
Watch out
In a 1280px window, 10cqw with no container-type anywhere above it came to 128px, the same as 10svw, and nothing warned about it.
Before
.card h2 {
font-size: clamp(1.25rem, 6cqw, 3rem);
}After
.card-wrap {
container-type: inline-size;
}
.card h2 {
font-size: clamp(1.25rem, 6cqw, 3rem);
}