Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Units and Values

Intrinsic sizing keywords

Reference for the intrinsic sizing keywords min-content, max-content and fit-content: what each measures, where they work and how they differ from auto.

Most sizes in CSS are decided by the container ("extrinsic" sizing). The intrinsic sizing keywords let the content decide instead. They go in width, height, min-width, max-width and their logical equivalents, and in grid track lists.

  • min-content is the smallest width at which the content does not overflow: for text, the width of the longest unbreakable word.
  • max-content is the width the content would take if it never wrapped: the full text on one line.
  • fit-content is max-content, but never more than the available space and never less than min-content.
CSS
.label { width: max-content; }
.card  { width: fit-content; max-width: 30ch; }

Try it

Three content-based widths

Syntax

CSS
width: min-content | max-content | fit-content | fit-content( <length-percentage> );

The keyword form of fit-content is the same as fit-content(stretch) in the spec. The function form clamps against a custom limit:

CSS
fit-content(<length-percentage>) = min(max-content, max(min-content, <length-percentage>))

Values

Value Description
min-content The narrowest size that avoids overflow, with every soft wrap opportunity used.
max-content The widest size: no soft wrapping. Long text can overflow its container.
fit-content max-content, limited by the space the container offers, and not below min-content.
fit-content(<length>) The same formula with your own limit instead of the available space.

Usage notes

  • fit-content is a "shrink-wrap" box. It is the usual choice for badges, tooltips and centered dialogs that should hug their text but wrap when space runs out.
  • max-content can overflow. Pair it with max-width: 100% if long content might exceed the container.
  • Images and replaced elements use their intrinsic dimensions (or aspect ratio) for these keywords.
  • Grid tracks. min-content, max-content and fit-content() are valid track sizes; see grid-template-columns.
  • Different from auto. A block's width: auto stretches to the container; fit-content shrink-wraps.
  • Percentages cannot be mixed in without care. fit-content(50%) resolves against the container's size, which must be definite.
  • Heights. On the block axis these keywords usually behave like auto, because height already follows content.

Browser support

The three keywords are supported in current browsers; older versions needed vendor prefixes, so check a compatibility table when you must support old browsers.