# grid-template-columns

> The `grid-template-columns` CSS property defines the column structure of a grid container.

## How do I make a responsive grid without media queries?

The property that defines the width of each column in a grid layout. Specific sizes, flexible units and repeating patterns can be applied, allowing precise control over the column structure and space distribution in the grid layout.

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

## Example

Wrong:

```css
.cards {
  display: grid;
  grid-template-columns: 25% 25% 25% 25%;
  gap: 16px;
}
```

Right:

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

Percentages plus `gap` overflow; `auto-fill` with `minmax()` fits as many columns as space allows.

## Common mistakes

- Using `25% 25% 25% 25%` with a gap, causing horizontal overflow.
- `1fr` columns grow wider than expected because of long words.

## Key points

- Responsive card grids use `repeat(auto-fill, minmax(min(250px, 100%), 1fr))`.
- Flexible tracks use `fr` instead of percentages, so `gap` doesn't cause overflow.
- `minmax(0, 1fr)` is used when columns hold long text or code that must not widen the track.

## Interview questions

### auto-fill vs auto-fit: what is the difference?

`auto-fill` keeps empty tracks when there are few items. `auto-fit` collapses empty tracks, so existing items stretch to fill the row.

### Why is my 1fr column wider than the others?

`1fr` has an automatic minimum, so long content pushes it wider. Use `minmax(0, 1fr)` to allow it to shrink.

## Related cards

- [repeat()](https://wonderium.dev/css/repeat.md)
- [minmax()](https://wonderium.dev/css/minmax.md)
- [fit-content()](https://wonderium.dev/css/fit-content.md)
- [gap](https://wonderium.dev/css/gap.md)
- [grid-template-rows](https://wonderium.dev/css/grid-template-rows.md)

---

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