function

fit-content() — CSS reference

In grid track sizing this caps a flexible intrinsic maximum using the argument, while respecting the track automatic minimum. In sizing properties the similarly named function uses the fit-content sizing formula with its argument in place of available space; support differs by context. Do not conflate the bare keyword with a grid track function.

Formal Syntax & Structure

css syntaxcss
fit-content(<length-percentage>)

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS sizing and overflow lab</title><style>body {margin:0} .sample {background:#dcebe9;color:#182e32}#p{display:grid;width:240px;grid-template-columns:fit-content(100px) 1fr} #a{font-size:0} span{display:inline-block;width:70px;height:10px}</style><body><div id="p"><div id="a" class="sample"><span></span><wbr><span></span></div><div id="b" class="sample"><span></span><wbr><span></span></div></div></body></html>
CSS Reference