coderef

fit-contentBaseline · Widely available

The fit-content CSS keyword expands a box as needed to fit its contents until the maximum size is reached, preserving the content's preferred aspect ratio.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Nov 2, 2021. Widely available since May 2, 2024.

Browser support

DesktopChrome
1–45Not supported
46+Supportedsince Oct 13, 2015
Current: 155
Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154
Firefox
1–93Not supported
94+Supportedsince Nov 2, 2021
Current: 157
Safari
1–10.1Not supported
11+Supportedsince Sep 19, 2017
Current: 27
MobileChrome Android
18–45Not supported
46+Supportedsince Oct 14, 2015
Current: 155
Firefox Android
4–93Not supported
94+Supportedsince Nov 2, 2021
Current: 157
Safari iOS
1–10.3Not supported
11+Supportedsince Sep 19, 2017
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: fit-content.

Feature detection

CSS · check before using
@supports (height: fit-content) {
  /* styles that rely on height: fit-content */
}

/* or in JavaScript */
if (CSS.supports("height", "fit-content")) {
  // use it
}

Sub-features

Support for each part of the feature (6). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
height.fit-content46799411469411
max-height.fit-content46799411469411
max-width.fit-content46799411469411
min-height.fit-content46799411469411
min-width.fit-content46799411469411
width.fit-content46799411469411