Grid

W3C CSS Snapshot 2026

Grid arranges content in rows and columns. Set display: grid on the parent to create a grid container. Define tracks and gaps on the container, then position or align individual items.

On this page

Grid container properties

  • display

    Create a grid container. Its direct children become grid items.

  • grid-template-columns

    Define the explicit columns. List track sizes from inline-start to inline-end.

  • grid-template-rows

    Define the explicit rows. The values are in block-axis order.

  • grid-template-areas

    Draw the grid as named areas. Write each row in quotes and keep each area rectangular.

  • grid-auto-columns

    Size columns the browser creates outside the explicit column list.

  • grid-auto-rows

    Size rows the browser creates outside the explicit row list.

  • grid-auto-flow

    Tell automatic placement whether to fill rows or columns first and whether to backfill gaps.

  • grid-template

    Set the explicit rows, columns, and optionally named areas in one declaration.

  • grid shorthand

    Set explicit or implicit grid properties. The shorthand resets omitted template and auto-placement properties to their initial settings.

  • gap

    Set the spaces between grid rows and columns. Gaps sit between tracks.

  • row-gap

    Set the gap between grid rows.

  • column-gap

    Set the gap between grid columns.

  • justify-items

    Set the default inline-axis alignment of items in their cells. This is left-to-right or right-to-left in horizontal writing modes.

  • align-items

    Set the default block-axis alignment of items within their cells.

  • justify-content

    Position the grid columns together on the inline axis when the grid is narrower than its container.

  • align-content

    Position the grid rows together on the block axis when the grid is shorter than its container.

  • place-items

    Set align-items and justify-items together on the container.

  • place-content

    Set align-content and justify-content together for the tracks inside the container.

Grid item properties

  • grid-column

    Choose where an item starts and ends along the columns. This shorthand sets grid-column-start and grid-column-end.

  • grid-row

    Choose where an item starts and ends along the rows. This shorthand sets grid-row-start and grid-row-end.

  • grid-column-start

    Set the start line for a grid item along its columns.

  • grid-column-end

    Set the end line for a grid item along its columns.

  • grid-row-start

    Set the start line for a grid item along its rows.

  • grid-row-end

    Set the end line for a grid item along its rows.

  • grid-area

    Place one item in a named area or set all four placement edges.

  • justify-self

    Override the inline-axis alignment for one grid item.

  • align-self

    Override the block-axis alignment for one grid item.

  • place-self

    Set align-self and justify-self together for one item.

  • order

    Change the order the grid uses for automatic placement. Keep the source order logical for reading and keyboard navigation.

Divide the available width with fr

grid-template-columns sets the size of each column. fr divides available space after fixed sizes and gaps. Two values of 1fr share that space equally. Items are placed across the track columns and then onto the next row.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Divide the available width with fr</title>
  <style>
    .cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
    .cards > div { background: #d6efea; padding: 12px; }
  </style>
</head>
<body>
<div class="cards"><div>Pen</div><div>Notebook</div><div>Folder</div></div>
</body>
</html>

What to expect Pen and Notebook fill the first row; Folder starts the next one. Try 1fr 2fr.

Place page regions with named areas

grid-template-areas draws a map using one quoted string per row. Repeating a name within a row lets that area span columns. Each named area must form a rectangle. Use a dot for an empty cell. grid-area assigns an item to a named spot.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Place page regions with named areas</title>
  <style>
    .page { display: grid; gap: 8px; grid-template-columns: 7rem minmax(0, 1fr);
      grid-template-areas: "head head" "side content"; }
    .page > * { background: #d6efea; padding: 8px; }
    header { grid-area: head; }
    aside { grid-area: side; }
    main { grid-area: content; }
  </style>
</head>
<body>
<div class="page"><header>Example Store</header><aside>Categories</aside><main>Pens and notebooks</main></div>
</body>
</html>

What to expect The header spans both columns. Categories appears next to the product list in the second row.

Related lessons

Official references