Dev Helpers

CSS / Box model and sizing

Width that follows content

Dev Helpers · November 3, 2025

A content-sized label can hug short text while still needing a boundary for long text. Intrinsic sizing lets the content influence the box.

Worked example

<style>
  .demo {
    width: fit-content;
    padding: 0.5rem 1rem;
  }
</style>
<div class="demo">Width that follows content</div>

Implementation notes

Long content can exceed a content-sized element even when the parent is fluid. Combine intrinsic sizing with a maximum and an appropriate word-breaking policy.

Try it yourself

Compare a short badge with an untranslated product identifier.

Open the CSS example →

Editorial date November 3, 2025 · Published December 6, 2026

Related articles

Fluid width with a maximum

A fluid container needs a small-screen width and a large-screen maximum. Outer gutters should remain visible at both extremes.

Square aspect ratio

A square ratio reserves equal sides even before media loads. Fit rules decide whether rectangular content is cropped or letterboxed.

Minimum inline size

A logical minimum inline size protects a component from collapsing beyond its usable width. An overly large minimum can force overflow.