Inspecting the Box Model in DevTools
The Box Model diagram in the Elements/Inspector panel is the fastest way to answer "why is there unexpected space here" or "what is this element's actual rendered size." It shows content, padding, border, and margin as nested, color-coded rectangles with live numbers on each side — reading it correctly turns spacing bugs from guesswork into a two-second lookup.
A worked example: tracking down mystery spacing
Here is the full workflow applied to a realistic bug report: "there is too much space between the page header and the first card, but I cannot find where it comes from."
Select the first card element in the Elements panel and check its box model diagram — the top margin shows 0, so the space is not coming from the card itself
Select the header element instead — its bottom margin shows 40px, which looks larger than the design calls for
Open the Computed panel for the header, filter for "margin", and click the arrow next to
margin-bottomto see which rule actually set itThe rule turns out to come from a shared
.section + .sectionsibling-combinator rule that also matches the header unintentionallyFix: scope the rule more precisely, or override it locally on the header with a smaller, deliberate margin
Where to find it
Open DevTools and select an element (right-click → Inspect, or the element-picker icon)
Open the Styles/Layout sidebar tab next to the Styles pane
Scroll to the bottom of the Styles pane (Chrome/Edge) or the dedicated "Layout" section (Firefox) to find the box model diagram
Reading the diagram
Layer (outside in) | Color (Chrome default) | What it represents |
|---|---|---|
Margin | Orange/yellow | Space outside the border, between this element and its neighbors |
Border | Yellow/tan | The border line itself, part of the box if |
Padding | Green | Space inside the border, before the actual content starts |
Content | Blue | The actual content box — where text/children render |
Live-editing values
Every number in the box model diagram is directly editable — double-click it, type a new value, and press Enter to see the layout update instantly, without touching the actual stylesheet. This is the fastest way to test "what if this padding were 8px larger" without a single file edit.
Double-click any margin/border/padding number to edit it in place
Changes are temporary (reset on reload) — copy the working value into your actual CSS once you find it
Combine this with the Styles pane above it: editing a value there updates the diagram live too, and vice versa
Verifying box-sizing
The single most common box-model confusion is forgetting whether an element uses content-box (the CSS default) or border-box. The Computed panel settles it immediately.
.card {
width: 300px;
padding: 20px;
border: 2px solid black;
}
/* content-box (default): rendered width = 300 + 40 + 4 = 344px
border-box: rendered width = 300px, padding/border eat into it */Select the element in the Elements panel
Open the Computed panel (next to Styles)
Search "box-sizing" in the filter box at the top
Compare the reported value against the width shown at the top of the box model diagram to confirm which model is in effect
Finding unexpected spacing
When a gap looks wrong, the box model diagram tells you immediately which layer is responsible — a wide gap between elements is almost always margin, while unexpected space between the border and the text content is padding.
Where the extra space appears | Likely layer |
|---|---|
Between two separate elements | Margin (check both elements — margins can collapse) |
Between an element's border and its own text/children | Padding |
Around an element even with margin: 0 and padding: 0 set | An ancestor's padding, or a pseudo-element ( |
Negative margins in the diagram
A negative margin pulls an element closer to (or past) its neighbors, and the box model diagram represents this by drawing the margin rectangle overlapping the content box rather than surrounding it. It looks unusual the first time you see it, but it is the same diagram, just with the margin value negative.
.overlap {
margin-top: -20px; /* pulls the element upward, overlapping its
previous sibling by 20px */
}Comparing box-sizing across two elements
A frequent real bug: two elements meant to be the same width render differently because one uses content-box and the other border-box. Selecting each in turn and comparing their Computed width side-by-side settles it in seconds.
Element | width (declared) | box-sizing | Rendered width |
|---|---|---|---|
| 300px | content-box (default) | 300 + padding + border |
| 300px | border-box | 300px exactly |
width, check box-sizing in the Computed panel for each before looking anywhere else — it is the single most common cause of this exact symptom.The ruler / measuring tools
Chrome and Firefox both let you hover over an element to see live pixel distances to nearby elements, without opening the full box model diagram
Firefox's "Measure a portion of the page" tool (in the DevTools toolbar) draws an on-page ruler for arbitrary distances, useful for confirming spacing against a design mockup
Holding a modifier key while hovering (varies by browser/version) shows distances from the hovered element to its containing block edges directly on the page
Chrome vs Firefox naming differences
The underlying concept is identical in both browsers, but the panel names and locations differ slightly, which trips people up when switching between them.
Concept | Chrome / Edge | Firefox |
|---|---|---|
Box model diagram location | Bottom of the Styles pane, or the dedicated "Layout" tab | Dedicated "Layout" panel, "Box Model" section |
Resolved final values | "Computed" tab | "Computed" tab (same name) |
Flex/grid overlay controls | "Layout" tab, same panel as box model | "Layout" panel, separate Flexbox/Grid sections |
Cross-checking with getComputedStyle in the console
The Elements panel is the visual tool, but the DevTools console gives you the same numbers programmatically — useful for comparing many elements at once, or for pasting exact values into a bug report.
/* Run in the DevTools console, with an element selected via $0 */
const style = getComputedStyle($0);
console.log({
width: style.width,
boxSizing: style.boxSizing,
padding: style.padding,
margin: style.margin,
border: style.borderWidth,
});$0 — DevTools always keeps this bound to whatever is currently selected in the Elements panel, so you can run arbitrary JavaScript against it without re-selecting it with a query selector.Properties that are easy to confuse
Property | Common confusion |
|---|---|
| Margin is outside the border (space between elements); padding is inside it (space before content) |
| Whether |
|
|
|
|
Box model checklist for a spacing bug
Select both elements bordering the unexpected gap, not just one — the space can come from either side, or both via margin collapse
Confirm
box-sizingin the Computed panel before assuming awidthvalue is wrongUse the Computed panel's "show which rule set this" arrow instead of scanning the whole Styles pane by eye
Watch for negative margins drawn inward in the diagram — they are easy to misread as zero at a glance
Live-edit values directly in the diagram to find the right number before writing it back into your stylesheet