Web site Developer I Advertising I Social Media Advertising I Content material Creators I Branding Creators I Administration I System Answer
Ahmad Shadeed covers the CSS fit-content
sizing key phrase. It’s helpful! It simply doesn’t come up tremendous typically. I discover myself utilizing min-content
much more, like when organising the peak of a grid-template-row
.
The fit-content
key phrase is definitely intently associated to min-content
and max-content
— it simply has a little bit heuristic it follows that Ahmad properly illustrates as a circulation chart.

My favourite use case is roofed right here: sizing a <determine>
with fit-content
, in order that it neatly wraps across the <img>
. That manner, even when the picture doesn’t fill the dad or mum area, and it may stay block-level.
We additionally coated PPK’s deep dive on fit-content
final 12 months. One of many key takeaways for understanding it’s figuring out that’s it basically a shorthand manner of writing:
.field {
width: fit-content;
/* ... is similar as ... */
width: auto;
min-width: min-content;
max-width: max-content;
}