Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Fractional Units and Minmax Sizing | Placing and Sizing Grid Items
CSS Grid Mastery

bookFractional Units and Minmax Sizing

Introduction to the fr Unit

When you want to build layouts that adapt smoothly to any screen size, the fr unit is a powerful tool at your disposal. The fr (fraction) unit in CSS Grid allows you to allocate a portion of available space to grid tracks. Unlike fixed units such as px or %, the fr unit distributes space dynamically, ensuring that your grid remains flexible and responsive.

If you set your grid columns to 1fr 2fr, the first column receives one part of the available space and the second column receives two parts, regardless of the overall grid width. This makes the fr unit essential for creating layouts that scale elegantly without manual adjustments.

index.html

index.html

styles.css

styles.css

copy

How minmax() Works and When to Use It

The minmax() function lets you define a size range for a grid track by specifying both a minimum and a maximum value. This approach is essential for responsive design because it prevents grid tracks from becoming too small to read or too wide to maintain a balanced layout.

  • Use minmax(min, max) to set a lower and upper size boundary for columns or rows;
  • Ensure content stays legible by setting a reasonable minimum value;
  • Allow tracks to expand and fill available space by pairing minmax() with fr units;
  • Maintain flexible, user-friendly layouts across all screen sizes.

For example, minmax(150px, 1fr) ensures a column will never shrink below 150px but can grow as large as available space allows. Apply minmax() when you want images, cards, or content blocks to remain readable and visually balanced, while still taking advantage of dynamic space distribution.

question mark

Which of the following grid-template-columns definitions will create three columns, where the first column is always at least 120px but can grow, the second column takes twice as much available space as the third, and the third column shares the remaining space?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 9.09

bookFractional Units and Minmax Sizing

Swipe to show menu

Introduction to the fr Unit

When you want to build layouts that adapt smoothly to any screen size, the fr unit is a powerful tool at your disposal. The fr (fraction) unit in CSS Grid allows you to allocate a portion of available space to grid tracks. Unlike fixed units such as px or %, the fr unit distributes space dynamically, ensuring that your grid remains flexible and responsive.

If you set your grid columns to 1fr 2fr, the first column receives one part of the available space and the second column receives two parts, regardless of the overall grid width. This makes the fr unit essential for creating layouts that scale elegantly without manual adjustments.

index.html

index.html

styles.css

styles.css

copy

How minmax() Works and When to Use It

The minmax() function lets you define a size range for a grid track by specifying both a minimum and a maximum value. This approach is essential for responsive design because it prevents grid tracks from becoming too small to read or too wide to maintain a balanced layout.

  • Use minmax(min, max) to set a lower and upper size boundary for columns or rows;
  • Ensure content stays legible by setting a reasonable minimum value;
  • Allow tracks to expand and fill available space by pairing minmax() with fr units;
  • Maintain flexible, user-friendly layouts across all screen sizes.

For example, minmax(150px, 1fr) ensures a column will never shrink below 150px but can grow as large as available space allows. Apply minmax() when you want images, cards, or content blocks to remain readable and visually balanced, while still taking advantage of dynamic space distribution.

question mark

Which of the following grid-template-columns definitions will create three columns, where the first column is always at least 120px but can grow, the second column takes twice as much available space as the third, and the third column shares the remaining space?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 3
some-alt