liveBook · Manning

Minmax()

As explained in Math for Web Design

minmax() is a CSS Grid sizing function that defines a track size within a specified minimum and maximum range.

A grid column that grows with the page can become too narrow to read. Use minmax(min, max) to give the track a minimum size while allowing it to grow toward a maximum. If max is smaller than min, the browser uses min. An fr value can be the maximum, but not the minimum. section 4.4.1

grid-template-columns: 3fr minmax(250px, 1fr);

In a 1200px container, the two columns initially divide space into four fractions: 900px and 300px. The second column exceeds its 250px minimum, so those widths stand. At 800px, its initial fraction would be 200px; the minimum instead gives it 250px and leaves 550px for the first column. section 4.4.1

grid-template-columns: repeat(4, minmax(250px, 1fr));

For product cards, repeat(4, minmax(250px, 1fr)) defines four columns that can share available space but cannot shrink below 250px. section 4.4.1

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

Combining minmax() with repeat(auto-fit, ...) gives a gallery flexible 180px-minimum columns while allowing the number of fitted columns to change. section 4.5

For a content-sized column, auto is close to minmax(min-content, max-content), but not identical: auto also respects applicable min-width and max-width constraints. Choose the bounds that match the layout you need. section 4.4.2

How Math for Web Design covers it

How deep it goes
Works through fractional-width calculations and minimum enforcement, but does not fully derive the grid track sizing algorithm.
Examples
Uses 1200px and 800px two-column calculations, a product-card grid, and an auto-fit gallery.
What it assumes
Introduces the needed fractional-track arithmetic through concrete widths while using CSS Grid declarations.
What you can do after
Apply it via CSS Grid to set flexible column widths with a minimum and calculate when that minimum takes effect.
How it connects
Connects minmax() to CSS Grid tracks, fr units, repeat(), auto-fit, and intrinsic sizing.

Also explained in

Compare how 2 books explain minmax() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.