Placing Items & Areas

Spanning Rows and Columns

Example

Items can span several tracks with grid-column and grid-row:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .container { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 50px; gap: 8px; }
    .container > div { background: #04AA6D; color: white; padding: 10px 16px; font: 15px Arial; }
    .wide { grid-column: span 2; background: #1971c2 !important; }
    .tall { grid-row: span 2; background: tomato !important; }
    .full { grid-column: 1 / -1; background: #282A35 !important; }
  </style>
</head>
<body>

<div class="container">
  <div class="wide">span 2 columns</div><div class="tall">span 2 rows</div><div>4</div>
  <div>5</div><div>6</div><div>7</div>
  <div class="full">1 / -1 (full width)</div>
</div>

</body>
</html>

Result

Named Template Areas

Example

Draw the layout with names. This is the most readable way to build a page layout:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    body { margin: 0; font-family: Arial; }
    .page {
      display: grid;
      grid-template-areas:
        "header header"
        "sidebar main"
        "footer footer";
      grid-template-columns: 140px 1fr;
      gap: 8px;
    }
    header { grid-area: header; background: #282A35; color: white; padding: 10px; }
    aside  { grid-area: sidebar; background: #e7e9eb; padding: 10px; }
    main   { grid-area: main; padding: 10px; min-height: 80px; }
    footer { grid-area: footer; background: #04AA6D; color: white; padding: 8px; }
  </style>
</head>
<body>

<div class="page">
  <header>Header</header>
  <aside>Sidebar</aside>
  <main>Main content</main>
  <footer>Footer</footer>
</div>

</body>
</html>

Result