SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
Grid FundamentalsGrid TracksGrid Placement and Layout DecisionsImplicit GridsFlexible GridsGrid AlignmentGrid or Flexbox Placing items on a grid
CSS Grid

Grid Alignment

Align and overlap items in a grid.

Grid has two kinds of alignment: moving items inside their areas, and moving the rows and columns as a group inside the container.

Align items within their areas

.labels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 6rem;
  align-items: center;
  justify-items: start;
  gap: 1rem;
}

In a horizontal writing mode, each label sits at the left of its area in left-to-right text, centered vertically. Unlike Flexbox, Grid's alignment axes do not switch through flex-direction:

PropertyWhat it aligns
align-itemsAll items within their areas on the block axis.
justify-itemsAll items within their areas on the inline axis.
align-selfOne item on the block axis.
justify-selfOne item on the inline axis.

For horizontal text, the block axis is vertical and the inline axis is horizontal. Inline start follows the text direction. Block start follows the writing mode, so in horizontal writing it stays at the top for both left-to-right and right-to-left text. Items with automatic sizes usually stretch to fill their areas, though images with a natural aspect ratio can behave differently.

Choose the axis

In horizontal left-to-right text, which property centers every item vertically inside its area?

Check your answer

Use align-items: center;: the block axis is vertical in this writing mode.

Now keep the other items at inline start and move only .featured to inline end. Which property belongs on that item?

Check your answer

Use justify-self: end; on .featured. It overrides the container's inline item alignment for that item.

Center an item on both axes

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

place-items: center sets both align-items and justify-items to center. With one child, that child is centered within its area. This shorthand does not center a Flexbox main axis because justify-items is ignored in flex layout.

For one exception in the label grid:

.labels > .featured {
  justify-self: end;
}

Its inline alignment changes while its siblings keep justify-items: start.

Distribute the tracks themselves

.small-grid {
  display: grid;
  width: 30rem;
  height: 20rem;
  grid-template-columns: repeat(2, 6rem);
  grid-template-rows: repeat(2, 4rem);
  gap: 1rem;
  justify-content: center;
  align-content: center;
}

The fixed tracks occupy less space than the container, so both content-alignment properties center the entire track group. By comparison, justify-items: center would only center each item inside its existing area.

If fractional tracks already consume all available inline space, there is no remaining inline room to move the track group.

Overlap items deliberately

.cover {
  display: grid;
}

.cover > * {
  grid-column: 1 / 2;
  grid-row: 1 / 2;
}

.cover > .badge {
  justify-self: end;
  align-self: start;
  z-index: 1;
}

Both children use the same cell. Set z-index to put the badge in front; grid items can use it without position. Make sure the overlap leaves text readable and controls reachable.

Key Takeaways

  • Items: The items and self properties align within assigned areas.
  • Tracks: The content properties distribute the track group when space remains.
  • Shorthand: place-items sets both item-alignment axes.
  • Overlap: Shared grid coordinates and z-index can create intentional layers.

Try it yourself

Try it yourself

Align labels

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

How is this lesson?

Previous lessonFlexible GridsNext lessonGrid or Flexbox
Edit on GitHubReport on GitHub
On this page
%

On this page

Align items within their areasChoose the axisCenter an item on both axesDistribute the tracks themselvesOverlap items deliberatelyKey TakeawaysTry it yourself