web-feature: fit-content

baseline logo 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.