10 / 21

How do you create equal-width columns using Grid?

Creating Equal-Width Columns with CSS Grid

In CSS Grid, you can create equal-width columns using the grid-template-columns property with the repeat() function and the fractional unit (fr). The fr unit distributes available space evenly among columns.

Key Points
  1. 1

    Use display: grid; to activate Grid layout.

  2. 2

    Define columns with grid-template-columns: repeat(n, 1fr); where n is the number of columns.

  3. 3

    The 1fr unit makes each column take an equal share of the available width.

  4. 4

    You can use the gap property to add spacing between columns.

Example: Three Equal-Width Columns