Intrinsic and Fluid Layouts
How to let content and the browser do the sizing with fluid widths, min() and clamp(), wrapping flex rows and auto-fit grids, so you need fewer breakpoints.
Viewport Units and Dynamic ViewportsCommon Flexbox PatternsAuto-Placement and Responsive Grids
Intrinsic and Fluid Layouts
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A page with no CSS is already responsive: blocks fill the width and text wraps. Most responsive bugs come from fixed sizes you add, so the best habit is to avoid declaring sizes you don't need.
- Fluid means sizes that are relative (`%`, `fr`, `ch`, `rem`). Intrinsic means sizes that come from the content (`min-content`, `max-content`, `fit-content`, `auto`). Modern layouts combine both.
- `width: min(100% - 2rem, 60rem)` with `margin-inline: auto` is a centered container that is capped at 60rem and keeps a 1rem gutter on either side. At 800px wide, a test measured 768px starting at x = 16.
- A wrapping flex row with `flex: 1 1 15rem` reflows by itself: at 600px wide three items made two rows (300px, 300px, then one 600px item), and at 800px they fit in a single row at about 267px each.
- Reading width belongs in `ch`: `max-width: 65ch` measures in the width of the character `0`, so line length tracks the font size.
Responsive before you write a rule
Open a page with no stylesheet and resize the window. Text wraps, headings stay inside the screen, nothing overflows. HTML is responsive by default. It is our CSS that breaks it, usually by adding sizes: a width: 960px here, a height: 400px there, and then a stack of media queries to patch what we broke.
Intrinsic and fluid layouts start from the other end. You work with the browser’s flexibility instead of replacing it. A good way to think about it: you are not drawing a layout for each screen size, you are writing rules about how things should behave when the space changes, and letting the browser work out the sizes.
Fluid and intrinsic
The two words get mixed up, so a quick split:
- Fluid sizes are relative to the environment:
%,vw,fr,rem,ch. They scale as the container or font changes. - Intrinsic sizes come from the content:
auto,min-content,max-content,fit-content. A button sized by its label is intrinsic.
Most good layouts use both. The skill is knowing which fits: reading text wants a fluid cap (65ch), a button wants an intrinsic size.
A container that adapts by itself
The classic centered wrapper needs two lines and no media query:
.container {
width: min(100% - 2rem, 60rem);
margin-inline: auto;
}
min() picks the smaller of its arguments. On a wide screen, 60rem wins and the container is capped. On a narrow one, 100% - 2rem wins, leaving a 1rem gutter either side. At 800px wide in a browser, the box measured 768px wide starting at x = 16. The math functions behind it are covered in values, units and math functions.
Prefer width: auto (or just not setting one) over width: 100% for blocks. auto fills the available space after margins and padding, while 100% plus padding can overflow.
Rows that reflow themselves
Flexbox with wrapping gives breakpoint-free reflow. Give items a preferred size and let them grow:
.row { display: flex; flex-wrap: wrap; gap: 1rem; }
.row > * { flex: 1 1 15rem; }
Each item wants 15rem, can grow to share space and can shrink. As the container narrows, the row wraps. In a test with three items and no gap, a 600px container made two rows, with two 300px items and then one 600px item, and an 800px container fit all three at about 267px each. Remember from the flexbox vs grid lesson that the last row’s items grow to fill the line. If you want them the same width as the rest, use a grid.
Grids that reflow themselves
The grid version, covered in auto-placement and responsive grids, keeps columns consistent:
.cards {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
}
Sizing with the content: ch and keywords
Line length is a readability problem, not a screen size problem, so it shouldn’t depend on a breakpoint:
.prose { max-width: 65ch; }
ch is roughly the width of a zero in the current font, so 65ch holds about 65 characters whatever the font size. A test with 16px text gave 520px. If the font changes size, the measure follows.
The intrinsic keywords size to content: width: max-content is as wide as the content wants with no wrapping, min-content is as narrow as it can get (the longest word), and fit-content is as wide as the content up to the available space. They are useful for labels, badges and sidebars.
Where media queries still belong
None of this means abandoning them. Use a media query when the layout has to change shape in a way sizing can’t express, like turning a navigation bar into a menu, or hiding a decorative element. The goal is fewer queries doing bigger jobs. Kevin Powell’s video makes the same split: its last chapter is about the times you will need media queries, after the chapters on letting the browser do the work.
What the video covers
Kevin Powell’s “A practical guide to responsive web design” (January 2024, about twenty-three minutes) has these chapters: websites are responsive before you write any CSS, avoid fixed sizes for your layouts, avoid declaring things you don’t need, viewport units won’t solve most of your responsive issues, letting the browser do the heavy lifting, and there are times you will need media queries. Its description links a free course on responsive layouts. I could not read a transcript, so I do not describe the demos. The min() container, wrapping-row numbers and ch examples are the prose’s own, checked in a browser. The runner-up shows five reusable breakpoint-free layouts: cluster, auto-grid, flexible grid, reel, and main with sidebar.
Where this fits
These techniques draw on flexbox, grid and the viewport units you have just seen, and they reduce the number of media queries you need. The next lesson, aspect ratio and responsive media, deals with the elements that bring their own proportions: images and video.
Check yourself
Why does the advice "avoid fixed sizes" help responsive design?
Block elements already fill the available width and text already wraps, so a page is flexible by default. A fixed `width: 800px` stops that and forces overflow on narrow screens. Use `max-width`, percentages or content-driven sizing so the browser can adapt.
What does `grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr))` do at three different container widths?
It fits as many columns of at least 15rem as the container allows and shares the leftover equally, so it goes from one column on a phone to two or more on wider containers with no media query. The `min(100%, 15rem)` stops a column from overflowing in a container narrower than 15rem.
What is the difference between a fluid and an intrinsic size?
A fluid size is relative to something external, like a percentage of the parent or a unit like `rem`. An intrinsic size comes from the content itself, for example `max-content` (as wide as the content wants) or `fit-content` (as wide as the content, up to the available space).
A line of body text runs across a 1400px screen and is hard to read. What is the simplest fix that works for every font size?
`max-width: 65ch`. The `ch` unit is about the width of a zero in the current font, so 65ch is roughly 65 characters per line regardless of font size or family.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.