A layout bug rarely announces itself. You get a card spilling two pixels past its container, a sidebar that refuses to sit beside the content, or a grid that looks right at 1280px and collapses at 900px. Staring at the CSS file rarely helps, because the file holds intentions while the browser holds the truth. DevTools is where the two get compared.
What follows is the routine worth running on every stubborn layout problem: inspect the right element, flip declarations on and off, read the grid and flex overlays, then isolate the line responsible.
Use the element picker — Ctrl+Shift+C on Windows and Linux, Cmd+Shift+C on macOS — instead of scrolling the DOM tree. Click the thing that looks wrong, not its parent. If the picker keeps grabbing a wrapper, press the arrow keys while it is active to move up and down the tree until the highlight matches what you see.
With the element selected, the Styles pane tells you which declarations applied and which lost. Learn to read the strike-throughs: a crossed-out rule lost to something more specific or later in the cascade. The Computed tab is the ground truth, showing final values after inheritance, shorthand expansion and relative units are resolved. A suspicious width of 50% might compute to 318.4px, and it is that number you debug against.
Below the styles sits the box model diagram. Hover over it and DevTools highlights the matching region on the page — content, padding, border, margin. A good share of "why is there space here" questions end right there, usually with a margin you forgot or padding inherited from a shared class.
Debugging is the business of eliminating candidates, and DevTools makes each test cost one click. Every declaration in the Styles pane has a checkbox. Untick one and watch the page. Untick three and you learn nothing useful, so go one at a time.
When you have a theory, add the declaration to element.style — the inline rule at the top of the Styles pane. It wins over almost everything except !important, so if the page snaps into shape, you know which property matters. Move it into the real stylesheet afterwards and check nothing else breaks.
One habit pays for itself immediately: use outline instead of border while debugging. An outline draws on top without affecting layout, so nothing shifts when you add or remove it. Paste a temporary rule such as * { outline: 1px solid magenta } into the Styles pane and the page becomes a wireframe in one keystroke.
Look for the small grid or flex badge next to an element in the Elements panel; clicking it toggles the overlay. In Chrome, the Layout pane — opened from the command menu with Ctrl+Shift+P and "Show Layout" — lists every grid and flex container on the page so you can switch them on in bulk. Firefox users get the same controls from the Layout tab, with a particularly good grid inspector.
For grid, the overlay draws tracks, line numbers and named areas. When an item lands in the wrong cell, the line numbers tell you whether your template is wrong or an explicit placement is fighting it. When a minmax() track behaves oddly, Firefox's track-size breakdown usually explains why.
For flex, the overlay exposes free space and how each item consumed it. That is where "why is this item twice as wide as the others" gets answered: the flex-basis, the growth factor, or the item's own content setting a minimum.
Horizontal scrollbars come from a short list of causes. Work through them in order:
To find the offender fast, run document.documentElement.scrollWidth in the Console and compare it with clientWidth on the same element. If the first number is larger, something is spilling. Then apply the outline trick and scan for the box that crosses the page edge — it is usually the last element in the DOM that does.
Two fixes cover most cases. Flex and grid items have an implicit minimum size, so a child with long content refuses to shrink until you give it min-width: 0 (or min-height: 0 in a column). For text, overflow-wrap: break-word handles long strings without hiding the problem behind overflow: hidden.
Most alignment bugs are axis mistakes. In flexbox, justify-content works along the main axis and align-items across it; switch flex-direction from row to column and the two swap meaning. Check the computed flex-direction first, then decide which property actually controls the direction you care about.
A few patterns are worth recognising on sight:
When a bug refuses to give in, fall back on this sequence. It is unglamorous and it works.
None of this depends on memorising properties. It depends on refusing to guess. DevTools shows you the box the browser actually rendered, and the distance between what you meant and what you wrote is always visible there.
Photo: Tranmautritam / Pexels
A practical walkthrough for planning your sections, writing semantic HTML, styling a responsive layout with modern...
A practical comparison of local coding meetups and online communities on feedback, networking, access and...
A practical guide to Advent of Code: how the December puzzle event works, how to handle its uneven difficulty, and...
Fuel your passion for coding and development.
Read More© 2026 Codice Mania · Theme by QuomodoTheme