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 Tracks

Define rows and columns in an explicit grid.

The rows and columns you define with template properties make up the explicit grid. Each track can have a fixed size, fit its content, or share available space.

Define columns and rows

.page {
  display: grid;
  grid-template-columns: 12rem 1fr;
  grid-template-rows: 4rem auto 3rem;
  gap: 1rem;
}

Each space-separated size defines one track:

  • Columns: A 12rem column followed by a flexible 1fr column.
  • Rows: A 4rem row, an automatic row, and a 3rem row.
  • Gap: Space between neighboring tracks on each axis.

This defines two columns and three rows. It does not automatically make an item span both columns; placement is a separate decision.

With an 800-pixel content width and a 16-pixel root font size, the first column uses 192 pixels and the gap uses 16. The flexible column receives the remaining 592 pixels when content minimums do not force it wider.

Complete a track list

A grid needs a 10rem column followed by two equal flexible columns. Finish the list after the first size:

.layout {
  display: grid;
  grid-template-columns: 10rem /* add two tracks */;
}
Check your answer

Use 10rem 1fr 1fr. Each value defines one track.

The repeat() function takes a count and a track pattern. How would you repeat 1fr four times, and how many columns would eight short items share?

Check your reasoning

repeat(4, 1fr) defines four columns. Eight items can fill two rows; the repeat count describes tracks, not items.

Choose a sizing approach

Track valueBehavior
12remA fixed length relative to the root font size.
autoUses automatic sizing that considers the items' content and available space.
1frReceives a share of leftover space, subject to its minimum.

Fixed row heights can be useful for a deliberate size, but text can outgrow them. The auto middle row can respond to its content. If a container has extra height, automatic rows can also stretch under the default content alignment.

fr rows share space in the grid, not the viewport. Give the container a set height when you want rows to divide a known amount of vertical space.

Repeat a track pattern

.three-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

repeat(3, 1fr) writes 1fr 1fr 1fr compactly. The count repeats the supplied track pattern; it does not limit the total number of items to three.

If six short articles use this grid, automatic placement fills two rows while preserving the same three column boundaries. Rows not explicitly listed are created as needed; the Implicit Grids lesson covers their sizing.

Keep percentage tracks and gaps in mind

Two 50% columns already consume the container's full width. Adding a nonzero gap can make the tracks overflow because the percentages do not automatically subtract the gap.

Use fr to divide the space left after gaps. A plain 1fr track still has a content-based minimum, so long text can make it wider. Flexible Grids shows how minmax() changes the minimum.

Key Takeaways

  • Explicit tracks: Template properties define the grid's intended rows and columns.
  • Mixed sizes: Fixed, automatic, and fractional tracks can coexist.
  • Repetition: repeat() abbreviates a track pattern, not an item limit.
  • Available space: Account for gaps, content minimums, and the container's dimensions.

Try it yourself

Try it yourself

Repeat three tracks

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 lessonGrid FundamentalsNext lessonGrid Placement and Layout Decisions
Edit on GitHubReport on GitHub
On this page
%

On this page

Define columns and rowsComplete a track listChoose a sizing approachRepeat a track patternKeep percentage tracks and gaps in mindKey TakeawaysTry it yourself