Course contentsShow
← Web Development
Lesson 342 of 2,9826. CSS GridFree lesson

Grid Template Sizing Best Practices

Learn strategies for choosing the right sizing approach based on content and layout goals.

Grid Template Sizing Best Practices

You'll learn how to choose the right track sizing method for different layout scenarios.

By now you've seen many ways to size grid tracks: fixed pixels, fr units, auto, minmax(), min-content, max-content, fit-content(), repeat(), auto-fill, and auto-fit. But when should you use each one?

Matching Sizing to Purpose

For flexible, proportional layouts, use fr units. They distribute available space fairly and adapt to container size:

grid-template-columns: 2fr 1fr; /* Sidebar gets 2/3, content 1/3 */

For content-driven sizing, use auto or min-content/max-content when the content should dictate track size, not the container.

For responsive grids without media queries, combine repeat(auto-fit, minmax()):

grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));

This creates cards that wrap automatically.

For constraining flexibility, use minmax() to set boundaries:

grid-template-columns: minmax(200px, 400px) 1fr;

The first column never shrinks below 200px or grows beyond 400px.

For text-based columns, fit-content() prevents excessive whitespace:

grid-template-columns: fit-content(300px) 1fr;

Think Like a Designer

Ask yourself: "Should this track grow? Shrink? Stay fixed? Respond to content?" Fixed pixels are predictable but inflexible. fr units are flexible but can create awkward empty space. minmax() gives you guardrails. Combining approaches often works best:

grid-template-columns: 250px minmax(300px, 2fr) minmax(200px, 1fr);

Key Takeaway: Choose sizing methods based on whether tracks should be fixed, flexible, content-driven, or constrained—and don't be afraid to mix approaches for real-world layouts.