# Container Query Units

> The container query units in CSS are relative length units based on the size of the query container.

## What are cqw and cqi units in CSS?

The units relative to the dimensions of the nearest size container, such as `cqw`, `cqh`, `cqi`, `cqb`, `cqmin` and `cqmax`. Allow sizing typography and spacing based on the component's container rather than the viewport.

- Topic: Measurement Units
- Type: concept
- Browser support: Chrome 105+, Chrome Android 105+, Edge 105+, Firefox 110+, Firefox Android 110+, Safari 16+, Safari iOS 16+

## Example

Wrong:

```css
.card-title {
  font-size: 5cqi;
}
```

Right:

```css
.card {
  container-type: inline-size;
}
.card-title {
  font-size: clamp(1rem, 5cqi, 2rem);
}
```

The `.card` container gives `cqi` a reference size, and `clamp()` with 'rem' keeps text readable and zoomable.

## Common mistakes

- Units act like viewport units because no ancestor is a size container.

## Key points

- An ancestor has `container-type` set; without one, the units resolve against the small viewport.
- `cqi` is used instead of `cqw` where sizes should follow the writing direction.
- Font sizes in container units are mixed with `rem` inside `clamp()`, so text still grows with user zoom.

## Interview questions

### What is the difference between cqw and cqi?

`cqw` is 1% of the container's width, while `cqi` is 1% of its inline size, which follows the writing mode.

### Do container query units need @container?

No. They only need an ancestor with `container-type`; an `@container` rule is optional.

### What do container units use when there is no container?

They fall back to the small viewport, so they act like `svw` and `svh`.

## Related cards

- [@container](https://wonderium.dev/css/container.md)
- [Viewport Units](https://wonderium.dev/css/viewport-units.md)
- [clamp()](https://wonderium.dev/css/clamp.md)
- [Relative Length Units](https://wonderium.dev/css/relative-length-units.md)
- [rem()](https://wonderium.dev/css/rem.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/container-query-units
- Last updated: 2026-11-25
