Skip to content

Alignment & Gaps

Grid doesn’t just place items — it manages space.

There are two different alignment stories:

  • how items align inside their cells
  • how the grid aligns inside its container

And one universal spacer: gap.


grid-template-columns: repeat(4, 1fr);
gap: 1rem;

gap:

  • works in both directions
  • doesn’t collapse
  • doesn’t leak outside the grid

Use it. Love it.


These affect how items sit within their grid areas:

  • align-items (block axis)
  • justify-items (inline axis)
align-items: center;
justify-items: stretch;

These affect how the entire grid is packed inside the container:

  • align-content
  • justify-content

They only matter when there’s extra space.


Change gaps.
Shift items.
Watch space move.


Grid gives you control over:

  • placement
  • spacing
  • alignment

Once you see the difference, the properties stop feeling redundant.


📘 Alignment and Gaps Study Guide (PDF)

📘 Alignment and Gaps Infographic (PNG)

Infographic explaining CSS Flexbox direction and axes, showing how flex-direction defines the main axis and cross axis, with visual examples for row, row-reverse, column, and column-reverse, and how justify-content and align-items map to each axis.

Pages, sections, components. Grids inside grids inside grids.