How to Make Equal-Width Columns with CSS Grid
Two declarations put items in columns of the same width: display: grid on the element that holds them, and grid-template-columns: repeat(3, 1fr) for three equal columns. The items fill the columns row by row.
Syntax
<container> {
display: grid;
grid-template-columns: repeat(<count>, 1fr);
}
| Part | What it does |
|---|---|
<container> | The element that holds the items. |
display: grid | Makes it a grid container. Its children become the grid's items. |
grid-template-columns | Sets the grid's columns. |
repeat(<count>, 1fr) | <count> columns of 1fr each, such as repeat(3, 1fr) for three. |
1fr | One share of the free space. Columns with the same number of fr get the same width. |
MDN's grid-template-columns page lists every value, and its flex value page says the fr unit represents a fraction of the leftover space in the grid container.
The Example
The example is a menu of six drinks in three equal columns. A thin border on each item shows where the columns are.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Grid columns</title>
<style>
.drinks {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.drinks p {
border: 1px solid #d1d1d1;
margin: 0;
}
</style>
</head>
<body>
<div class="drinks">
<p>Coffee</p>
<p>Tea</p>
<p>Juice</p>
<p>Water</p>
<p>Milk</p>
<p>Lemonade</p>
</div>
</body>
</html>
The second rule gives each item a border and removes the space a paragraph normally has above and below it, so the cells are easy to see.
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- The six drinks sit in three equal columns. In a window 480 pixels wide, each column was about 155 pixels wide.
- The items filled the grid row by row: Coffee, Tea and Juice in the first row, then Water, Milk and Lemonade in the second. The grid added the second row by itself.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out the comma: repeat(3 1fr) | The value is invalid and ignored, so the grid had one column and the items stood one under the other | Write repeat(3, 1fr) |
Leaving out display: grid | grid-template-columns does nothing on its own: the items stayed one under the other | Add display: grid to the same rule |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| One column is much wider than the others | A long word in it: a 1fr column grew to fit Pneumonoultramicroscopicsilicovolcanoconiosis, and the columns became 75, 314 and 75 pixels wide | Use repeat(3, minmax(0, 1fr)) |
| All items are in one column | The grid isn't on, or the repeat() value is invalid | Check display: grid and the comma in repeat() |
With minmax(0, 1fr), the columns stayed 155 pixels each, and the long word ran on into the next column instead.
FAQ
How do I make two or four columns?
Change the count. With repeat(2, 1fr), the items sat in two columns.
Can the columns have different widths?
Yes, give them different shares. MDN's flex value page shows 1fr 1fr 2.5fr 1.5fr, where the third column gets 2.5 shares of the free space.
Conclusion
Put display: grid and grid-template-columns: repeat(<count>, 1fr) on the element that holds the items, and they line up in columns of the same width. Switch to minmax(0, 1fr) when long words must not stretch a column.
Additional Resources
- grid-template-columns, on MDN.
- repeat(), on MDN.
- minmax(), on MDN.
