Size text with container query units
Container query units let text respond to a component’s space. 1cqi is one percent of the eligible container’s inline size, which usually means its width in horizontal writing.
That is useful for a promotional panel reused in several layouts. It is less useful when a heading becomes tiny because the panel happens to be narrow.
Put limits around the container query unit
<div class="promo-slot">
<section class="promo">
<h2>Photographs from the coast</h2>
<p>A collection of quiet places beside the Baltic Sea.</p>
</section>
</div>
.promo-slot {
container-type: inline-size;
}
.promo h2 {
font-size: 1.75rem;
font-size: clamp(1.75rem, 1rem + 3cqi, 3rem);
}
The first declaration gives older browsers a fixed size. The second combines a root-relative value with a container-relative contribution, bounded by a minimum and maximum.
This is a component-sized variation on fluid typography, rather than a reason to make all text depend on box width.
Without a query container, the units use the viewport
If there is no eligible query container, container units fall back to small viewport units for the corresponding axis. That can make a snippet appear to work while measuring something you never intended. MDN documents the fallback.
Keep the container declaration close to the component’s usage. Inspect the actual ancestor when nested containers produce unexpected sizes.
Test reading, not just resizing
Try a narrow sidebar, a wide content area, browser zoom, and increased default text size. Combining rem and cqi does not automatically prove that text can enlarge enough or avoid clipping.
For ordinary article text, a stable readable size is often the better choice. Save container-dependent scaling for elements whose visual role genuinely changes with their available space.