Mixing fr Units with Fixed Sizes
What you'll learn: How to combine fr units with fixed measurements like px, em, or % to create flexible layouts with elements that maintain specific sizes.
The Core Idea
When you define a grid, you don't have to choose only fr units or only fixed sizes—you can mix them! This is incredibly powerful because it lets you say "this column should always be 200px wide" while other columns flexibly share the remaining space using fr units.
Think of it like a restaurant table: some seats might be fixed booths built into the wall (fixed sizes), while other chairs can slide around to use whatever space is left (fractional units). The fixed elements take their space first, then fr units divide what remains.
How It Works
Fixed sizes (px, em, %) are calculated first and claim their exact space. After that, any leftover space is distributed among the fr units proportionally.
For example:
.container {
display: grid;
grid-template-columns: 200px 1fr 1fr;
}
Here, the first column will always be exactly 200px wide. The remaining space in the container is then split equally between the second and third columns (each gets 1fr of what's left).
.sidebar-layout {
display: grid;
grid-template-columns: 250px 2fr 1fr;
}
This creates a fixed 250px sidebar, then divides the remaining space so the middle column gets twice as much as the right column.
Common Pattern: Fixed Sidebar with Flexible Content
This pattern is perfect for app layouts where navigation needs consistent width, but content areas should adapt to screen size.
Key Takeaway: Mixing fr units with fixed sizes (px, em, %) lets you create layouts where some elements stay constant while others flexibly share the remaining space—fixed elements claim their space first, then fr units divide what's left.