Sub topic 1
Why intrinsic layouts: fewer breakpoints, more flexibility
Prerequisites
This chapter assumes you already know:
- Basic CSS syntax and how the cascade resolves conflicting rules.
- Common length units:
px,rem,em,%, andvw. - The box model and the
widthproperty. - Basic CSS Grid, such as
grid-template-columns.
Two ways to make a layout responsive
A responsive layout adapts to the space it is given. There are two common approaches.
A breakpoint-driven layout uses media queries. You pick viewport widths, such as 600px and 900px, and write a different set of rules for each range.
An intrinsic layout lets values adjust continuously. You describe limits and preferences, and the browser works out the result from the space available. The word "intrinsic" refers to sizing driven by content and container, not by fixed device categories.
The cost of breakpoints
Here is a typical breakpoint-driven container:
.container {
width: 100%;
padding-inline: 1rem;
}
@media (min-width: 640px) {
.container { width: 600px; margin-inline: auto; }
}
@media (min-width: 1024px) {
.container { width: 960px; margin-inline: auto; }
}This works, but it has weaknesses:
- Between breakpoints, the layout is fixed. At 700px the container is 600px wide, which wastes 100px.
- Each new component tends to add its own queries, so the stylesheet grows.
- Breakpoints are tied to the viewport. A component placed in a narrow sidebar still sees a wide viewport and does not adapt.
- Breakpoints encode assumptions about devices. New screen sizes fall between them.
The same container, intrinsic
Comparison functions let one declaration do the work of several rules:
.container {
width: min(100% - 2rem, 60rem);
margin-inline: auto;
}min() returns the smaller of its arguments. On a narrow screen, 100% - 2rem is smaller, so the container fills the width minus a 1rem gutter on each side. On a wide screen, 60rem is smaller, so the container stops growing. There are no media queries, and no width is left unused between breakpoints.
The next chapters cover min(), max(), and clamp() in detail. For now, the point is that the browser resolves the value for every width, not only at chosen breakpoints.
What you gain
| Concern | Breakpoint-driven | Intrinsic |
|---|---|---|
| Values between breakpoints | Fixed | Continuous |
| Amount of CSS | Grows with each query | One declaration per property |
| Unexpected screen sizes | May look awkward | Usually handled |
| Fine-tuning | Edit many rules | Edit one expression |
What intrinsic layouts do not replace
Intrinsic techniques do not remove media queries. Some changes are structural, such as moving a navigation menu into a drawer or switching between one and two page regions. Those still suit media queries or container queries. A good approach is to use comparison functions for sizing and spacing, and keep queries for the few real layout changes.
Exercise
Exercise
A container uses width: min(100% - 2rem, 60rem). The parent is 500px wide and 1rem is 16px. What is the container's width, and which argument of min() determines it?
Show answer
100% - 2rem is 500px - 32px = 468px. 60rem is 960px. The smaller value is 468px, so the first argument determines the width. The container fills the parent minus a 16px gutter on each side.