The essentials

Quick reference

One focused task per row. Jump to the related section for complete, working examples.

UseSyntaxExamples
Use the minimum intrinsic width.label { inline-size: min-content; }View examples
Use the maximum intrinsic width.label { inline-size: max-content; }View examples
Fit within available space.panel { inline-size: fit-content; }View examples
Cap a grid trackgrid-template-columns: fit-content(18rem) minmax(0, 1fr);View examples
Cap shrink-to-fit width.popover { width: fit-content(28rem); max-width: 100%; }View examples
Build intrinsic card tracksgrid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));View examples
Let a flexible track shrinkgrid-template-columns: minmax(0, 1fr) minmax(12rem, 24rem);View examples
Allow a flex item to shrink.content { min-inline-size: 0; }View examples
Break emergency text.message { overflow-wrap: anywhere; }View examples
Enable language-aware hyphenation.copy { hyphens: auto; overflow-wrap: break-word; }View examples
Contain preformatted overflowpre { max-inline-size: 100%; overflow: auto; }View examples
Supply a skipped-content estimate.card { content-visibility: auto; contain-intrinsic-size: auto 24rem; }View examples
Isolate size calculation.widget { contain: inline-size; }View examples
Layer a keyword fallback.chip { width: auto; width: max-content; max-width: 100%; }View examples
Measure overflowelement.scrollWidth > element.clientWidthView examples
Size a label column intrinsicallygrid-template-columns: min-content minmax(0, 1fr);View examples
Keep controls unwrappedgrid-template-columns: max-content minmax(0, 1fr);View examples
Constrain the logical axis.dialog { inline-size: fit-content; max-inline-size: min(42rem, 100%); }View examples

Intrinsic sizes come from content and formatting rules rather than a fixed viewport measurement. They are powerful for labels, cards, and tracks, but long tokens, replaced media, automatic minimum sizes, and indefinite available space can change the result. This guide pairs intrinsic keywords with the constraints that keep real interfaces responsive.

Step by step

Detailed examples

01

Understand the three content-based choices

min-content is the smallest intrinsic inline size under the applicable soft-wrapping rules; max-content is the size when soft wraps are not taken; fit-content clamps a preferred content size between its intrinsic minimum and available space. These are algorithmic sizes, not universal measurements of text. Padding, borders, box-sizing, replaced elements, white-space, and formatting context all influence the final used size.

Content-sized labels with hard limits
.labels { display: flex; flex-wrap: wrap; gap: .5rem; }
.label { inline-size: max-content; max-inline-size: 100%; overflow-wrap: anywhere; }
Back to quick reference ↑
02

Distinguish the keyword from the function

The fit-content keyword is accepted by sizing properties. fit-content(<length-percentage>) is prominently used as a grid track sizing function: it behaves like max(minimum, min(limit, max-content)) with the precise track rules from Grid. Support for the function on ordinary width and inline-size has historically differed, so pair it with max-inline-size and a preceding broadly supported declaration when that context matters.

Capped navigation rail and flexible content
.layout {
  display: grid;
  grid-template-columns: fit-content(18rem) minmax(0, 1fr);
  gap: 1rem;
}
Back to quick reference ↑
03

Defuse automatic minimum sizes

Grid and flex items often have an automatic minimum based on content. That safety can make a 1fr track or flex item overflow when it contains an unbreakable URL, preformatted code, or wide media. Use minmax(0,1fr) for a grid track or min-inline-size:0 on the item when the design intends it to shrink, then decide whether the content wraps, clips, or scrolls. Do not set zero minimums blindly on controls whose labels must remain perceivable.

A resilient sidebar layout
.shell { display: grid; grid-template-columns: minmax(12rem, 20rem) minmax(0, 1fr); }
.main { min-inline-size: 0; }
.main pre { overflow: auto; }
Back to quick reference ↑
04

Make intrinsic contributions reflect real text

white-space and breaking properties alter intrinsic sizes. overflow-wrap:anywhere creates emergency opportunities considered in min-content sizing; overflow-wrap:break-word provides emergency wrapping but does not reduce min-content in the same way. hyphens:auto needs correct language metadata and dictionary support. For code or data where arbitrary breaks harm comprehension, prefer a scroll container with a visible affordance.

Language-aware prose and scrollable code
<p class="copy" lang="de">Donaudampfschifffahrtsgesellschaft</p>
<pre><code>https://example.test/a/very/long/resource</code></pre>
Choose wrapping by content type
.copy { hyphens: auto; overflow-wrap: anywhere; }
pre { max-inline-size: 100%; overflow: auto; }
Back to quick reference ↑
05

Use containment with a deliberate placeholder

Intrinsic sizing can require examining descendants. content-visibility:auto may skip off-screen rendering; contain-intrinsic-size supplies a placeholder and the auto form can remember a previously rendered size. inline-size or size containment changes how descendants contribute to the container, which can materially change intrinsic layouts. Use estimates close to actual content to limit scrollbar jumps and cumulative layout shift.

Skip distant cards with a stable estimate
.feed-card {
  content-visibility: auto;
  contain-intrinsic-size: auto 22rem;
}
Back to quick reference ↑
06

Layer constraints and test hostile content

Place a broadly supported auto or fixed rule before an intrinsic enhancement. @supports can test syntax but not whether a chosen size remains usable with localization, zoom, or loaded fonts. Test narrow containers, 400% zoom, long untranslated tokens, missing images, variable-font swaps, vertical writing, and user text spacing. DevTools grid overlays plus scrollWidth/clientWidth checks help locate the box that is actually overflowing.

Progressive content-sized popover
.popover { inline-size: auto; max-inline-size: min(100%, 30rem); }
@supports (inline-size: fit-content) { .popover { inline-size: fit-content; } }
Back to quick reference ↑
07

Use logical sizes and definite constraints

Percentages need a definite containing size to resolve; intrinsic sizing can therefore behave differently in indefinite grid or flex calculations. Replaced content contributes natural dimensions and aspect ratios. Logical inline-size and block-size follow writing mode, while width and height are physical. Bound intrinsic results with min(), max(), max-inline-size, or an overflow policy rather than assuming max-content will fit the viewport.

Intrinsic form columns that still shrink
.field { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .5rem 1rem; }
.field input { min-inline-size: 0; inline-size: 100%; }
Back to quick reference ↑

Local code tester

Stress-test intrinsic card sizing

Change the wrapping selector to see how long localized labels affect min-content, max-content, and a capped flexible track.

Runs in your browser
Preview

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. CSS Working GroupCSS Box Sizing Module Level 3drafts.csswg.org
  2. CSS Working GroupCSS Box Sizing Module Level 4drafts.csswg.org
  3. CSS Working GroupCSS Grid Layout Module Level 2drafts.csswg.org
  4. World Wide Web ConsortiumCSS Flexible Box Layout Module Level 1w3.org
  5. MDN Web DocsIntrinsic sizedeveloper.mozilla.org

Help us improve

Found a typo or missing example?

Tell us what would make this cheat sheet clearer, more complete, or more useful.

Share feedback