CSS Reference ยท Grid
The grid-auto-columns property
Reference for the CSS grid-auto-columns property: size the implicit columns a grid creates automatically, with track values, minmax(), examples and notes.
The grid-auto-columns property sizes the implicit columns of a grid, which are the columns the browser adds when an item is placed beyond the columns declared by grid-template-columns. It matters most with grid-auto-flow: column, where every new item gets a new column.
If you list several sizes, they repeat in order for as many implicit columns as are needed.
CSS
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 120px; }
Try it
Syntax
CSS
grid-auto-columns: <track-size>+; /* <track-size> */ <length-percentage> | <flex> | min-content | max-content | auto | minmax( <inflexible-breadth>, <track-breadth> ) | fit-content( <length-percentage> )
- Initial value:
auto - Applies to: grid containers
- Inherited: no
- Animatable: yes, between lists with the same number of compatible values (lengths and percentages); other values change abruptly
- Computed value: the list, with lengths made absolute
Values
| Value | Description |
|---|---|
auto |
Sized by content, and stretches to take up free space if justify-content is normal or stretch. |
<length> / <percentage> |
A fixed width or a share of the grid container's width. |
<flex> (1fr) |
A share of the remaining space. |
min-content / max-content |
The narrowest or widest the content can be. |
minmax(min, max) |
A range, such as minmax(100px, 1fr). |
fit-content(limit) |
Content width, but never wider than the limit. |
| Several values | Used in sequence and repeated for further implicit columns. |
Usage notes
- Only implicit columns. It never changes columns defined in
grid-template-columns. - Horizontal scrollers.
grid-auto-flow: columnplusgrid-auto-columns: minmax(200px, 1fr)andoverflow-x: autogives a card carousel without extra markup. repeat()isn't allowed here except as the list itself; write the sizes out.autois not a width of zero. An empty implicit column still takes its gap.- Implicit columns appear by placement too. An item with
grid-column: 6in a 3-column grid creates columns 4 to 6 using this property.
Browser support
Supported in all current browsers.
Related
grid-auto-rows- the same for rowsgrid-auto-flow- controls placement directiongrid-template-columns- explicit columns- Lesson: Grid Tracks