Jul 30, 2025
This lecture introduces the CSS minmax()
function, explaining its usage in grid layouts to set flexible size ranges for grid tracks.
minmax()
CSS function sets a size range between a minimum and maximum value.minmax()
ensures a grid track is at least the minimum value and at most the maximum value specified.minmax(min, max)
, where both min
and max
are required.<length>
, <percentage>
, <flex>
value, or keywords like max-content
, min-content
, and auto
.max
is less than min
, the maximum is ignored and the track size becomes the minimum value.<length>
: A non-negative fixed value (e.g., 200px
).<percentage>
: A non-negative percentage relative to the grid container.<flex>
: A non-negative unit (fr
) that distributes remaining space proportionally.max-content
: Uses the largest required space for content.min-content
: Uses the smallest required space for content.auto
: As a minimum, uses the largest min size of items; as a maximum, behaves like max-content
but can expand via alignment properties.grid-template-columns: minmax(200px, 1fr) 1fr 1fr;
defines a column that is at least 200px but can grow to fill available space.grid-template-columns
, grid-template-rows
, grid-auto-columns
, and grid-auto-rows
.fr
units that allows proportional space sharing.minmax()
in CSS Grid layouts.