How do min-content, max-content, and fit-content work in CSS Grid?

It tests intrinsic track sizing. A strong answer defines min-content as the smallest no-overflow width, max-content as widest no-wrap width, and fit-content as clamped max-content; then shows labels hugging longest word.
WHAT THIS TESTS: This question probes your understanding of intrinsic sizing in CSS Grid and how the browser resolves track sizes based on content rather than explicit lengths. It reveals whether you know the difference between minimum and maximum intrinsic contributions, how the grid container distributes leftover space, and when to reach for content-based keywords instead of fixed or fractional units.
A GOOD ANSWER COVERS: First, define min-content as the smallest size a track can shrink to before its content overflows, which for text is usually the width of the longest word or unbreakable element. Second, define max-content as the largest size a track would need if its content could lay out on a single line without wrapping, representing the upper bound of the content's natural width. Third, explain fit-content as a value that behaves like max-content but is clamped by the available space in the container, effectively capping expansion so the track does not push the grid beyond its bounds; if space is tight it can still compress down to min-content. Fourth, apply these definitions to the specific declaration grid-template-columns: auto 1fr min-content by describing a layout where the first column sizes to its own content with auto, the middle column absorbs all free space with 1fr, and the final column shrinks to the intrinsic minimum of its content, such as a set of action buttons or labels that should stay compact without wrapping.
COMMON WRONG ANSWERS: A red flag is treating auto and fit-content as interchangeable; auto distributes leftover space after content sizing and can grow well beyond max-content, whereas fit-content hard-caps growth at the container limit. Another mistake is claiming these keywords are exclusive to Grid when they also apply to Flexbox and other layout contexts, even though the question focuses on Grid. Some candidates also describe max-content as the largest possible viewport width rather than the content's own unwrapped width, or they suggest min-content equals zero, confusing it with min-width zero.
LIKELY FOLLOW-UPS: An interviewer might ask how fit-content differs from the fit-content function with an argument, such as fit-content(200px), which lets you supply your own cap instead of using the container size. They might also ask what happens when multiple tracks use min-content and max-content simultaneously and the grid is constrained, which tests your understanding of the grid sizing algorithm and how the browser balances intrinsic contributions against fractional units.
ONE CONCRETE EXAMPLE: Imagine a settings panel with three columns: a category label on the left, a fluid input field in the middle, and a Delete button on the right. Using grid-template-columns: auto 1fr min-content, the left column hugs the label text, the input stretches to fill remaining space, and the right column collapses to the exact width of the Delete button text plus padding because min-content prevents the button from wrapping or expanding. If the button label were longer, the column would grow only enough to hold that longest word, keeping the layout crisp and predictable.
Source: developer.mozilla.org
Read the original → developer.mozilla.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.