π What is grid-auto-columns?
grid-auto-columns is a CSS Grid container property that defines the width of any columns that are created automatically (implicit columns). These columns appear when grid items are placed outside the explicitly defined columns.
π Why Do We Need grid-auto-columns?
- Some items may span more columns than explicitly defined
- The grid may auto-generate new columns when items overflow horizontally
- Without defining their size, implicit columns may become unpredictable
- Ensures consistent column width for dynamic or auto-flowing layouts
π― Syntax
grid-auto-columns Syntax
grid-auto-columns: <track-size>;π§ What Are Implicit Columns?
Implicit columns are columns created automatically by the browser when items:
- Overflow the defined grid columns
- Use grid-column: span x and exceed the explicit structure
- Are placed using grid-auto-flow: column
- Donβt fit into the available columns
Note
π§ͺ Basic Example
Simple Auto Column Example
.container {
display: grid;
grid-template-columns: 150px 150px; /* explicit columns */
grid-auto-columns: 100px; /* width of implicit columns */
}Any additional columns generated by overflow or spanning will have a width of 100px.
π Visual Example

π₯ Example: Horizontal Auto-Flow
grid-auto-flow: column Example
.container {
display: grid;
height: 300px;
grid-auto-flow: column; /* β items fill columns first */
grid-auto-columns: 120px;
}When items fill columns first, new columns are created implicitly β their width is controlled by grid-auto-columns.
π§© Masonry-Like Example Using auto Columns
Masonry Using Implicit Columns
.gallery {
display: grid;
grid-auto-flow: column dense;
grid-auto-columns: 12px; /* base width for scaling */
}
.gallery .item {
grid-column: span 20; /* width = 20 Γ 12px */
}This pattern allows pixel-perfect masonry layouts where item widths are determined by column spans using very small base units.
π± Responsive Example
Responsive auto columns
.cards {
grid-auto-columns: 150px;
}
@media (min-width: 900px) {
.cards {
grid-auto-columns: 200px;
}
}Implicit columns become wider on larger screens.
β οΈ Common Mistakes
- Expecting it to affect explicit columns (it wonβt)
- Forgetting implicit columns exist until items overflow horizontally
- Misunderstanding grid-auto-flow direction
- Using fixed sizes without considering content resizing
Note
Implicit columns are created most often when using grid-auto-flow: columnor when items span multiple columns beyond what you've defined.
π grid-auto-columns vs grid-template-columns
| Property | Controls |
|---|---|
| grid-template-columns | Explicitly defined columns (exact structure you set) |
| grid-auto-columns | Implicit columns auto-created by the browser |
π₯ Summary
grid-auto-columns gives you control over how automatically created (implicit) columns behave. It is essential for dynamic grids, column-flow layouts, and masonry-style designs where items extend beyond the defined template.
Learn more βMDN Docs π