0Pricing
CSS Academy · Lesson

Gap and Grid Placement

Add space between grid cells with gap and place items using grid-column and grid-row.

Gap and Grid Placement is a free CSS Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Gap in CSS Grid

The gap property sets the space between grid rows and columns. It replaces the older grid-gap property and also works in Flexbox.

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px; /* equal row and column gap */
}

row-gap and column-gap

Set row and column gaps independently:

.grid {
  row-gap: 32px;
  column-gap: 16px;
  /* or: gap: 32px 16px; (row column) */
}

Grid Line Numbers

CSS Grid numbers its lines starting at 1. A 3-column grid has column lines 1, 2, 3, 4. Negative numbers count from the end: -1 is the last line, -2 is second to last.

grid-column and grid-row

Place items manually using line numbers with grid-column and grid-row:

.header {
  grid-column: 1 / 4;  /* span all 3 columns */
  grid-row: 1;          /* first row */
}

.main {
  grid-column: 1 / 3;
  grid-row: 2;
}

Span Keyword

Use span to express how many tracks an item should cover instead of absolute line numbers:

.featured {
  grid-column: span 2; /* covers 2 columns from its auto-placed position */
  grid-row: span 2;    /* covers 2 rows */
}

Negative Line Numbers

Negative indices count from the end. 1 / -1 always spans the full grid width regardless of column count:

.full-width {
  grid-column: 1 / -1;
}

grid-area Shorthand

grid-area sets all four grid placement values in one property: row-start / column-start / row-end / column-end.

.hero {
  grid-area: 1 / 1 / 2 / -1;
  /* row 1 start, col 1 start, row 2 end, last column */
}

Auto Placement

Items not explicitly placed are auto-placed in the next available cell following the grid-auto-flow algorithm. The browser fills cells left to right, top to bottom by default.

justify-items and align-items on Grid

On a grid container, justify-items aligns cell content horizontally; align-items aligns vertically. Both default to stretch.

.grid {
  display: grid;
  justify-items: center;
  align-items: start;
}

justify-self and align-self

Individual grid items can override the container's alignment using justify-self and align-self:

.featured-card {
  justify-self: stretch;
  align-self: center;
}

Overlapping Grid Items

Multiple items can occupy the same grid cell. Use z-index to control which appears on top. This enables layered designs like image + overlay text.

.image { grid-area: 1/1/3/3; z-index: 0; }
.caption { grid-area: 2/1/3/3; z-index: 1; }

Quick Check

An item has grid-column: 2 / span 3. Which columns does it occupy in a 5-column grid?

Recap

gap adds gutters between grid cells. Items are placed using line numbers with grid-column and grid-row. The span keyword specifies how many tracks to cover. Use 1 / -1 to always span all columns. Grid items can overlap using z-index.

Frequently asked questions

Is the “Gap and Grid Placement” lesson free?

Yes — the full text of “Gap and Grid Placement” is free to read here on the web, and the CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO.

What will I learn in “Gap and Grid Placement”?

Add space between grid cells with gap and place items using grid-column and grid-row. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CSS Academy?

No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Gap and Grid Placement” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CSS Academy lesson?

Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Display Grid and Template Columns Rows
  2. The fr Unit and Repeat
  3. Gap and Grid Placement
  4. Grid Template Areas
← Back to CSS Academy