Sub topic 7
Fixed and Fluid Grids Compared
This chapter assumes you know basic CSS units (px, rem, %), the box model, and the idea of columns, gutters, and margins from the earlier chapters. You will compare the two ways to size a column grid, work out the actual column widths each produces, and learn which one to use and why most real sites end up with a mix of both.
What "fixed" and "fluid" mean
A fixed grid uses absolute sizes for its columns and gutters. The grid has one total width, and it does not change when the browser window changes.
A fluid grid (also called a liquid grid) uses relative sizes. Columns are fractions or percentages of the space available, so the grid stretches and shrinks with the container.
The difference is what the browser does with leftover or missing space:
| Situation | Fixed grid | Fluid grid |
|---|---|---|
| Window wider than the grid | Empty space appears around the grid | Columns grow to fill the space |
| Window narrower than the grid | Horizontal scrollbar or clipped content | Columns shrink to fit |
| Column width | Same at every viewport width | Changes continuously with viewport width |
| Gutter width | Constant | Constant if set in rem, variable if set in % |
A fixed grid in CSS
In a fixed grid, every track has a length. Here each of the twelve columns is 4rem wide and each gutter is 1.5rem.
.grid-fixed {
display: grid;
grid-template-columns: repeat(12, 4rem);
column-gap: 1.5rem;
width: max-content;
margin-inline: auto;
}The total width is the sum of all columns and all gutters. With 12 columns there are 11 gutters:
12 × 4rem + 11 × 1.5rem = 48rem + 16.5rem = 64.5remAt a 16px root font size that is 1032px. A viewport narrower than that forces horizontal scrolling.
Using rem instead of px does not make the grid fluid. The grid still ignores the viewport width. It only scales when the user changes the font size, which is a useful accessibility benefit but a different thing from fluidity.
A fluid grid in CSS
In a fluid grid the columns share whatever width the container has. The fr unit divides the free space after gutters are subtracted.
.grid-fluid {
display: grid;
grid-template-columns: repeat(12, 1fr);
column-gap: 1.5rem;
padding-inline: 1rem;
}The column width follows a formula:
column width = (container width − total gutter width) ÷ number of columnsWith a 1.5rem (24px) gutter, 11 gutters take 264px. The table shows what happens to each column at three viewport widths, with 16px of padding on each side:
| Viewport | Content width | Column width |
|---|---|---|
| 320px | 288px | (288 − 264) ÷ 12 = 2px |
| 768px | 736px | (736 − 264) ÷ 12 ≈ 39.3px |
| 1280px | 1248px | (1248 − 264) ÷ 12 = 82px |
The 320px row shows the main weakness of a fluid grid. The gutters are constant, so on a narrow screen they consume almost all the space and the columns become useless. A fluid 12-column grid with large gutters does not work on a phone. The next chapters deal with this by changing the column count at breakpoints.
Fluid grids and the `1fr` overflow trap
1fr is shorthand for minmax(auto, 1fr). The auto minimum means a track will not shrink below the minimum content size of its items. A long unbroken string, a wide table, or a pre block can push a track wider than its share and cause overflow.
.grid-safe {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
column-gap: 1.5rem;
}With minmax(0, 1fr) the tracks can shrink to zero, so the column widths stay equal. The overflowing content then needs its own handling, such as overflow-wrap: anywhere for text or overflow-x: auto on a table wrapper. Use minmax(0, 1fr) whenever a grid holds content you do not control.
The usual answer: fluid inside a maximum width
Pure fixed grids waste space on large screens and break on small ones. Pure fluid grids stretch without limit, so lines of text become too long to read on a wide monitor. Most production layouts combine the two: the grid is fluid, but its container has a maximum width.
.page {
box-sizing: border-box;
max-width: 72rem;
margin-inline: auto;
padding-inline: 1rem;
}
.grid {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
column-gap: 1.5rem;
}This behaves in two phases:
- Below 72rem (1152px), the container is as wide as the viewport. The grid is fluid and the columns change width continuously.
- Above 72rem, the container stops growing and centers itself. The grid is effectively fixed, and the extra space becomes outer margin.
Because of box-sizing: border-box, the 1rem padding is included in the 72rem. At the maximum, the content is 1120px wide and each column is (1120 − 264) ÷ 12 ≈ 71.3px.
Choosing between them
The right choice depends on the content and the audience. Use these criteria:
| Question | Points toward fixed | Points toward fluid |
|---|---|---|
| Do users view the page on many device sizes? | No, one known size | Yes |
| Does the layout need pixel-exact alignment, such as an ad slot or image of a set size? | Yes | No |
| Is it mostly reading text? | Cap the width | Fluid up to a cap |
| Is the content a flexible set of cards or images? | Rarely | Yes |
| Do you maintain the CSS over years? | Fewer moving parts | Needs breakpoints and testing |
For almost every public website, the fluid grid with a max-width container is the default. A strictly fixed grid is reasonable for an internal tool used on known screens, or for an element with a fixed-size part such as an ad.
Edge cases and failure modes
- Fractional pixels. A fluid column of 39.33px cannot be drawn exactly. Browsers round positions, so you may see a one-pixel difference between neighboring columns or hairline gaps between adjacent backgrounds. Avoid pixel-precise borders that depend on exact column edges.
- Mixed units. Setting columns in
frand gutters in%makes the gutter change with the container as well, and a percentagecolumn-gapresolves against the grid container's content width. Preferremgutters so the spacing stays predictable. - Fixed columns inside a fluid page. A
repeat(12, 4rem)grid placed in a narrow container overflows it. If you need some fixed tracks, mix them with a flexible one, for examplegrid-template-columns: 12rem 1fr. - Too-wide lines. On a fluid grid with no cap, a text column that spans 8 of 12 columns on a 2560px monitor produces lines far beyond the readable range of roughly 45 to 80 characters. The
max-widthcontainer prevents this. - Zoom behavior. Because rem-based sizes scale with the root font size, a user who sets a larger default font reaches the horizontal-overflow limit sooner in a fixed rem grid. A fluid grid adapts as the effective viewport shrinks.
Summary
A fixed grid gives predictable column sizes but ignores the viewport. A fluid grid follows the viewport but can produce columns that are too narrow or lines that are too long. A fluid grid inside a max-width, centered container combines the strengths of both. Use minmax(0, 1fr) to keep tracks equal and rem gutters to keep spacing stable.
Exercise
A fixed grid has 12 columns of 5rem each and a 1.5rem column gap. What is its total width in rem and in px (root font size 16px)? Then, for a fluid grid with a 1rem gap and a content width of 1000px, what is each of the 12 columns' width, rounded to one decimal place?
Show answer
Fixed grid: 12 × 5rem + 11 × 1.5rem = 60rem + 16.5rem = 76.5rem, which is 1224px at 16px per rem. Fluid grid: 11 gutters × 16px = 176px, so each column is (1000 − 176) ÷ 12 = 824 ÷ 12 ≈ 68.7px.
Exercise
Why does a grid declared as repeat(12, 1fr) sometimes overflow its container when one item contains a very long unbroken word, and how do you prevent it?
Show answer
1fr means minmax(auto, 1fr), so a track cannot shrink below its content's minimum size and the long word keeps its track wide. Use repeat(12, minmax(0, 1fr)) so tracks can shrink below content size, and let the long word wrap with overflow-wrap: anywhere or scroll inside its own wrapper.