fit-content()
The fit-content() CSS function, used outside of a grid layout property, clamps a length between min-content and max-content.
Overview
The fit-content() CSS function, used outside of a grid layout property, clamps a length between min-content and max-content.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
css.properties.block-size.fit-content_function Experimental | | | 91 | | | |
| CSS property | ||||||
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental `fit-content()` | | | 91 | | | |
fit-content function Experimental The fit-content() CSS function clamps a given size to an available size according to the formula min(maximum size, max(minimum size, argument)). | | | 91 | | | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Notes 1 item(s)
Experimental
- Requires an experimental browser flag to be enabled
Syntax
CSS
.tag {
width: fit-content(200px);
padding: 0.25em 0.5em;
background: #e5e7eb;
border-radius: 4px;
} Live demo
Use cases
Component layout
Use fit-content() to create more predictable spacing and placement inside reusable UI patterns.
Responsive structure
Adapt containers and flow rules so layouts stay stable across viewport changes.
Cautions
- Test layout rules with real content, long labels, and small screens before depending on them broadly.
- Prefer simpler layout primitives if they already solve the problem clearly.
Accessibility
- Layout choices should preserve reading order and support zoom without clipping.
- Avoid visually clever positioning that makes content harder to follow with keyboard or assistive tools.
Related links
Powered by web-features