Skip to content
Back to all posts
Technology

CSS Grid Cheat Sheet: Columns, Rows, Areas, and Responsive Layouts

A practical CSS Grid reference with repeat(), minmax(), auto-fit, alignment, named areas, and responsive layout examples.

3 min read

TechSilo

Technology writer & developer

CSS Grid handles two-dimensional layout: you can position content by columns and rows without combining floats or complicated width calculations.

Start with a simple grid

css
.dashboard {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  gap: 1.25rem;
}

The sidebar occupies 16rem, while the main region takes the remaining space. minmax(0, 1fr) allows long content to shrink instead of forcing horizontal overflow.

The most useful properties

| Property | Purpose |

| --- | --- |

| display: grid | Turn an element into a grid container |

| grid-template-columns | Define explicit columns |

| grid-template-rows | Define explicit rows |

| gap, row-gap, column-gap | Space between tracks |

| grid-column | Place or span an item across columns |

| grid-row | Place or span an item across rows |

| place-items | Shorthand for align-items and justify-items |

| place-content | Align the entire grid when free space exists |

Repeat tracks without hard-coding every width

css
.gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

For truly responsive cards, let the browser decide how many columns fit:

css
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 1rem;
}

Here auto-fit collapses unused tracks, while auto-fill preserves empty track slots. The min(100%, 16rem) guard prevents a minimum card width from overflowing narrow phones.

Span columns and rows

css
.featured {
  grid-column: 1 / -1; /* Across the full explicit grid */
}
.metrics {
  grid-row: span 2; /* Occupies two row tracks */
}

Avoid forcing visual order to differ from the HTML source order. Keyboard focus and screen readers generally follow the DOM order, not the layout positions.

Named grid areas

css
.page {
  display: grid;
  grid-template:
    "header header" auto
    "aside  main" 1fr
    "footer footer" auto
    / 15rem minmax(0, 1fr);
  gap: 1rem;
}
header { grid-area: header; }
aside  { grid-area: aside; }
main   { grid-area: main; }
footer { grid-area: footer; }

@media (max-width: 48rem) {
  .page {
    grid-template:
      "header" auto
      "main" 1fr
      "aside" auto
      "footer" auto / minmax(0, 1fr);
  }
}

Named areas are useful when the same layout needs different arrangements across breakpoints.

Center anything inside a grid

css
.centered {
  display: grid;
  place-items: center;
  min-height: 20rem;
}

Debug checklist

If a grid overflows, inspect the minimum sizes of its children, long unbroken words, and the difference between 1fr and minmax(0, 1fr). Use browser DevTools' grid overlay to see each track. For small components where only one direction matters, Flexbox may be simpler.

Pair this reference with the [CSS Color Tools](/tools/color-tools) when you are styling a responsive interface.

Want to put this into practice?

Explore TechSilo's free developer tools for practical utilities you can use directly in your browser.

Related blog posts