liveBook · Manning

Minmax()

As explained in CSS in Depth, Second Edition

The CSS minmax() function defines a range containing a minimum and maximum size for a grid track.

The CSS minmax() function constrains a grid track between a minimum and maximum size. With minmax(200px, 1fr), each column stays at least 200px wide while sharing available space. section 5.4

Responsive portfolio columns

Use grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); to fit as many columns as the available width allows without making any column narrower than 200px. Wider screens fit more columns; narrower screens fit fewer. section 5.4

Keep these behaviors in mind:

  • The first argument supplies the minimum size and the second supplies the maximum. section 5.4
  • If the maximum is smaller than the minimum, the maximum is ignored. section 5.4
  • auto-fill may create empty tracks when there are not enough grid items to occupy them. section 5.4
Listing 5.9 A grid with implicit grid rows
body {
  background-color: #709b90;
  font-family: Helvetica, Arial, sans-serif;
}

.portfolio {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));     #1
  grid-auto-rows: 1fr;                 #2
  grid-gap: 1em;
}

.portfolio > figure {
  margin: 0;          #3
}

.portfolio img {
  max-inline-size: 100%;
}

.portfolio figcaption {
  padding: 0.3em 0.8em;
  background-color: rgb(0 0 0 / 0.5);    #4
  color: #fff;
  text-align: right;
}

Inspect a complete portfolio rule using repeat(), auto-fill, minmax(), and implicit grid rows. section 5.4

How CSS in Depth, Second Edition covers it

How deep it goes
Explains minimum and maximum arguments, conflict resolution, and responsive behavior through an applied grid example.
Examples
Uses a responsive photograph portfolio with repeat(auto-fill, minmax(200px, 1fr)) and automatically placed items.
What it assumes
Assumes familiarity with grid containers and tracks while defining minmax() through a concrete portfolio layout.
What you can do after
Apply it via CSS Grid to build columns that remain usable while expanding or contracting with the viewport.
How it connects
Connects CSS Grid track sizing with repeat(), auto-fill, fractional units, and implicit grid rows.

Also explained in

Compare how 2 books explain minmax() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.