06 / 21

What does the grid-template-columns property do?

Understanding grid-template-columns in CSS Grid

The grid-template-columns property in CSS Grid defines the number, size, and width of the columns in a grid container. It sets up the vertical tracks along which grid items are placed.

Key Points
  1. 1

    Defines the number of columns in the grid.

  2. 2

    Specifies the width of each column using lengths (px, em), percentages (%), fractions (fr), or auto.

  3. 3

    Supports the repeat() function for repeating columns with the same size.

  4. 4

    Works in combination with grid-template-rows to define the full grid structure.

  5. 5

    Example: grid-template-columns: 1fr 2fr 1fr; creates three columns with the middle column twice as wide as the others.

Example: Using grid-template-columns