# minmax()

> The `minmax()` CSS function defines a size range for a grid track, between a minimum and a maximum.

## How do I make responsive grid columns with minmax() in CSS?

The math function used in grid layouts to define a size range for grid tracks. It specifies a minimum and maximum size for rows or columns, allowing for flexible layouts that adapt to varying amounts of content or viewport sizes.

- Topic: Mathematics
- Type: function
- Browser support: Chrome 57+, Chrome Android 57+, Edge 16+, Firefox 52+, Firefox Android 52+, Safari 10.1+, Safari iOS 10.3+

## Example

Wrong:

```css
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 300px);
}
```

Right:

```css
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
}
```

Columns now stretch to fill the row, and `min()` stops a column from overflowing screens narrower than '300px'.

## Common mistakes

- A grid column overflows because `1fr` has an automatic minimum of the content width.
- Cards overflow narrow screens because the `minmax()` minimum is wider than the viewport.

## Key points

- Flexible columns that hold long content use `minmax(0, 1fr)` instead of `1fr`.
- Responsive card grids use `repeat(auto-fill, minmax(200px, 1fr))` instead of media queries for each column count.
- `fr` is not used as the minimum value, which is invalid.

## Interview questions

### What is the difference between auto-fill and auto-fit with minmax()?

`auto-fill` keeps empty tracks when items run out. `auto-fit` collapses them, so the items stretch to fill the row.

### Why does 1fr not shrink below the content width?

`1fr` means `minmax(auto, 1fr)`, so the minimum is the content size. Use `minmax(0, 1fr)` to let it shrink.

### Can I use minmax() in flexbox?

No. `minmax()` only works in grid track sizes like `grid-template-columns` and `grid-auto-rows`.

## Related cards

- [grid-template-columns](https://wonderium.dev/css/grid-template-columns.md)
- [repeat()](https://wonderium.dev/css/repeat.md)
- [grid](https://wonderium.dev/css/grid.md)
- [min()](https://wonderium.dev/css/min.md)
- [grid-auto-rows](https://wonderium.dev/css/grid-auto-rows.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/minmax
- Last updated: 2026-11-25
