OnlineCBT Logo OnlineCBT
CSS Tutorial
CSS · LESSON 29

Grid Fractional Unit (fr) and Repeat Function

By Ratan Updated: 15 Oct 2026

Create dynamic grid layouts using fractional units (fr) and the repeat() function.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Share remaining track space with fr

The fr unit represents a flexible share of available grid space after other relevant track sizing. It is not simply a percentage of the entire container. repeat reduces repetition in a track list.

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

The equal grid creates three flexible tracks. The split grid distributes flexible space in a 1:2 ratio, subject to track constraints. Gaps consume space separately; they are not extra percentages to add on top of a full-width calculation.

Why minmax(0,1fr) is useful

A plain 1fr track has an automatic minimum that can be influenced by content. A long unbreakable token can therefore keep the track wider than expected. minmax(0,1fr) permits a zero minimum while sharing available space. It does not automatically wrap the content inside the track.

Repeat syntax

grid-template-columns: repeat(4, 8rem);
/* Equivalent to four consecutive 8rem tracks. */
grid-template-columns: 12rem repeat(2, minmax(0, 1fr));

The second rule creates a fixed first column followed by two flexible columns. Fixed widths are appropriate only when the available container can accommodate them or a responsive rule provides an alternative.

Do not confuse tracks with items

Three columns do not limit the grid to three items. Auto-placement puts additional items into following rows. Each item may also span tracks, so item count and column count are separate concepts.

Exercises and answers

  1. Create six cards in a three-column grid; expect two rows under ordinary placement.
  2. Change repeat(3,...) to repeat(2,...); expect three rows.
  3. Place a long URL in one card and compare 1fr with minmax(0,1fr), then add wrapping.
  4. Explain why 50% 50% plus a nonzero gap can overflow: the percentages already consume the full available width.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat