grid-auto-columns

Term side of the Card.
Topic: Grids
Unit title: grid-auto-columns
Categories: Property
Explanation side of the Card

Explanation: The property that sets the size of columns in a grid container that are automatically generated. When items are placed outside the defined grid, this property controls the width of those additional columns, ensuring they fit within the layout.

Browser compatibility:
  • The chrome browser supports this feature starting from version 57.
  • The edge browser supports this feature starting from version 16.
  • The firefox browser supports this feature starting from version 70.
  • The safari browser supports this feature starting from version 10.1.
Availability: 

Example

Wrongcss
.carousel {
  display: grid;
  grid-auto-flow: column;
}
Rightcss
.carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 80%;
  overflow-x: auto;
}

grid-auto-columns sizes every new column, so each slide takes 80% width and the row scrolls.

Common mistakes

  • Expecting grid-auto-columns to size columns already set by grid-template-columns.

Key points

  • Horizontal auto-flow layouts pair grid-auto-flow: column with grid-auto-columns.
  • Implicit column sizes use minmax() or a fixed size when items must not collapse.

Interview questions

grid-auto-columns vs grid-template-columns: what is the difference?

grid-template-columns defines explicit columns. grid-auto-columns sizes columns the grid creates on its own for extra items.

What is the default value of grid-auto-columns?

It is 'auto', so implicit columns size to their content.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy