Whatβs the difference between fr units and % in CSS Grid layouts?

Below is a complete explanation of the difference between fr units and % percentage units in CSS Grid, with diagrams (text-based), examples, best practices, and real-world use cases.
β Difference Between fr Units and % in CSS Grid Layouts
(Code & Deep Explanation)
CSS Grid offers powerful ways to size columns and rows. Two of the most commonly compared units are:
frβ fraction of the remaining free space%β percentage of the total container width
They may look similar, but their behavior is fundamentally different.
π΅ 1. What Is fr in CSS Grid?
fr stands for fractional unit, and it divides the remaining available space inside the grid container after subtracting:
- padding
- border
- gaps
- fixed-width tracks
βοΈ Key Features of fr
- Automatically divides leftover space.
- Naturally responsive.
- Adjusts itself even when container size changes.
- Accounts for grid gaps automatically.
- Prevents overflow because it distributes only leftover space.
π§© Example 1 β Using fr
.grid {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
gap: 20px;
}
JavaScriptπ How it works:
Total fr units = 1 + 2 + 1 = 4
- Column 1 β 1/4 of remaining space
- Column 2 β 2/4 (half the width)
- Column 3 β 1/4
The grid automatically subtracts gap and padding, then distributes space.
βοΈ Responsive
Works perfectly on all screen sizes without adjustment.
πΆ 2. What Is % in CSS Grid?
Percentage (%) units divide the width based on the full container width, not the leftover width.
βοΈ Key Features of %
%is strict and does NOT care about gaps or borders.- If columns add up to more than 100%, overflow happens.
- Content inside columns may break the layout.
- Less flexible and less βintelligentβ than
fr. - Responsive only in a basic sense.
π§© Example 2 β Using %
.grid {
display: grid;
grid-template-columns: 25% 50% 25%;
}
JavaScriptπ Behavior:
- Columns take exactly 25%, 50%, 25% of the container width.
- Grid gaps are not subtracted automatically.
- Risk of overflow if total > 100%.
π₯ 3. Technical Difference in Calculation
| Unit | Based On | Considers Gaps? | Flexible? | Risk of Overflow? |
|---|---|---|---|---|
fr | Remaining space | βοΈ Yes | β Very Flexible | β No |
% | Full container width | β No | β οΈ Semi-flexible | βοΈ Yes |
π§ 4. Why fr Is Usually Better Than % in Grid
βοΈ fr distributes only leftover space
β No surprises, no overflow.
βοΈ % ignores gaps
β 33% + 33% + 33% + gap = overflow.
βοΈ fr naturally scales
β Perfect for modern responsive layouts.
βοΈ % tries to force columns into fixed ratios
β Old-school responsive design.
π§© 5. Side-by-Side Example (fr vs %)
π Using fr
.grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 20px;
}
JavaScriptβ₯οΈ Using %
.grid {
display: grid;
grid-template-columns: 33% 33% 33%;
gap: 20px;
}
JavaScriptπ Result:
frversion: perfect spacing, grid adapts even with gaps.%version: 99% + gap β overflow, forcing layout to stretch or wrap.
βοΈ 6. Mixing fr with Fixed Units produces intelligent results
Example:
grid-template-columns: 200px 1fr 1fr;<br>JavaScript- First column is fixed.
- Remaining width is shared equally by the two
frcolumns.
With %, the same layout is harder because the container width changes.
π§± 7. Real-World Analogy
π¦ fr = βSplit the leftover pizza equally after removing reserved slices.β
If someone takes a fixed slice (px), the rest gets divided fairly.
π© % = βDivide the whole pizza into percentages regardless of who already took some slices.β
If someone takes more or gaps exist, the math breaks.
π 8. When to Use Which?
βοΈ Use fr when:
- You want a flexible layout
- You donβt want overflow issues
- You use gaps
- You want auto-responsiveness
- You want columns to βshare spaceβ logically
βοΈ Use % when:
- You need exact, fixed proportional sizing
- You want precise alignment with external designs (e.g., Figma)
- You are recreating old float-based or grid frameworks
π 9. A Practical Responsive Grid Example
Using fr units
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
JavaScriptOn small screens
@media (max-width: 600px) {
.grid {
grid-template-columns: 1fr;
}
}
JavaScriptβοΈ Gets perfect responsiveness
βοΈ No calculation needed
βοΈ No overflow issues


