Two boxes on the saffron co-op's price page. Both declare width: 300px, both have padding: 20px and border: 2px, and rendered side by side they are visibly different widths.
width: 300pxwith padding 20 and border 2 makes a box 344px wide by defaultbox-sizing: border-boxmakes width the total, so the same box is 300px
The first is the original rule: width means the content, and the padding and border are added outside it. Three hundred plus forty plus four. Nobody has ever wanted that, which is why * { box-sizing: border-box } is the one line nearly every stylesheet starts with, and why a layout that is mysteriously wider than its container is almost always this and nothing else.
Learn the arithmetic rather than the rule, because it is the same arithmetic in every debugging session: a width, plus its padding twice, plus its border twice, is what the element occupies, and margin is on top of that and belongs to the space around it rather than to the box. That is margin, border, padding, and where widths go wrong.
Two layout systems, and the choice is one question
Flexbox lays out along one axis and grid lays out in two. That sentence decides it almost every time: a row of buttons, a navigation bar, a label next to a field are one axis; a page with columns and rows that have to line up in both directions is two.
Picking one
The same five questions put to flexbox and to grid
No winner marked, because there is not one. The first row decides it and the rest follow from that.
Both use gap, and both are in every browser that matters. Nothing here is a transition from an old system to a new one; they were designed for different jobs and shipped a year apart.
Interactive Practice Lab
Edit and run this snippet directly in your browser (zero setup)
.demo { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px;}.box { flex: 1 1 80px; text-align: center; background: #0ea5e9;}Live Big-O Complexity & Binary Search Race Lab
Compare complexity curves at scale and watch Linear vs Binary Search race live.
Inside flexbox the two properties worth knowing on the first day are a pair, and they are easy to get the wrong way round. justify-content moves items along the main axis, align-items across it, so on a row of city names justify-content spreads them left to right and align-items lines up their tops or centres. Rendered on 2026-09-01: three names with space-between sit at the edges and the middle, and with align-items: center a taller item centres against the shorter ones instead of stretching.
Both systems took the same improvement: gap replaces margins between flex and grid children, so the spacing belongs to the container rather than to each child, and no child needs a rule removing the margin from the last one. Those are laying out along one axis and laying out in two dimensions.

The layout that answers the screen without being told about it
One line does most of what people write media queries for. grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) wraps without a media query: put four city cards in a 480 pixel container and they arrange themselves as two by two, and in a wider one as four across, with no breakpoint written anywhere.
Responsive rules
From guessed screen widths to content-driven layout
Intrinsic grid sizing removes most breakpoints by stating the minimum card width instead of guessing device sizes.
How layout adapts
- Media queriesSwitches rules at fixed viewport widths
- Container queriesAsks how wide the parent column actually is
- repeat(auto-fit, minmax(220px, 1fr))Wraps four cards into two by two inside 480px
A card only cares how wide its own column is. Use auto-fit first, container queries when rules must change, and media queries last.
That is worth preferring because a breakpoint is a guess about a screen size and this is a statement about the content: no card narrower than 220 pixels, and as many as fit. Where a real breakpoint is still needed, a media query changes the rules at a width, and container queries ask the parent instead, which is the newer and usually more correct question, because a card does not care how wide the phone is, only how wide its own column is. That is one document, every screen.

What to run in 2026
The browser's own element inspector is the tool, free, and it is where this work is actually done: it shows the computed box with its four numbers, says which rule won and which was struck through, and lets a value be dragged. It replaced adding a coloured outline to find out where something was.
One element
What the four rings add up to, read from the inside out
Every debugging session about a width is this arithmetic, and the default rule counts only the innermost ring.
- width: 300pxContent300 pixels, and the only thing the default width refers to
- 02Padding20 each side, inside the border and painted with the background
- 03Border2 each side, which is where the box visibly ends
- 04MarginOutside the border, belongs to the space around the box, and collapses against its neighbour
The rings are not to scale. What is to scale is the sum: three inner rings make 344 pixels, and border-box makes the same three add to 300 by shrinking the content.
Sass is still around and does much less than it did. It replaced a stylesheet with no variables, no nesting and no way to split a file, and CSS has since taken back all three: custom properties are variables that also work at run time, nesting shipped natively, and imports are handled by the tooling. What is left is genuine but small, and it is variables, nesting and what CSS took back.
A checker for reduced motion belongs here too. transform and opacity are the two properties that animate without relayout, so animating anything else asks the browser to work out the whole page sixty times a second, and it is the one performance rule in this language that a beginner can apply immediately. That is transitions, keyframes and what stays cheap.
The mistake: fighting a rule you have not read
The stall in this language is specific and it has a name in every team: the declaration that does nothing. Something is set, nothing moves, and the response is to set it again more forcefully, then to add an important, then to add a more specific selector, and an hour later the stylesheet has three rules doing the work of none.
Debugging
Three reasons a CSS rule does nothing
Stacking more selectors or adding !important misses the real cause. The element inspector shows which branch happened.
- Property does not applyElement display type ignores it
- width set on an inline element
- Needs block or inline-block context
- Container decides sizeValue applied, parent overrode it
- Flex child sized by flex-basis
- Grid track template controls width
- Another rule wonCascade chose a different value
- Shown struck through in inspector
- Higher specificity or later rule
Open the inspector before the second attempt, not after the fifth. Seeing which rule won or which parent owns sizing fixes it in one edit.
Almost always one of three things is true and the inspector says which in a second. The property does not apply to that element, which is what happens when width is set on an inline element. Another rule won, and it is shown struck through with the winner above it. Or the value is being applied and something else is deciding the size, which on a flex or grid child is usually the container rather than the child.
So the habit is to open the inspector before the second attempt, not after the fifth. The co-op's price table was fixed by one word, because the cards were flex children and their width was being decided by flex-basis, and no amount of width on the card was ever going to win that argument.
What this page does not settle is where the styles live once there are two hundred of them and four people editing, which is a question about components rather than about CSS and belongs with building an interface out of components. The tree all of this is arranged over is the structure under every page, and what it costs to draw is why a page feels slow, and what actually fixes it.
