Testing the box model

Run the Inspect box model bookmarklet, then click any sample. A panel should report how the box of the element you clicked is put together. Press Esc to stop.

Each sample has a small grey label above it showing the CSS used and the values you should expect in the panel. Click the coloured box, not the label.

The panel reads from the inside out: box-sizing, Content, Padding, Reserved space (scrollbar gutter), Border, Outline, Margin, then Total and Gap above. Four-sided values collapse to shorthand, so 18px 24px when the sides pair up and 1px 2px 3px 4px when they do not. The highlight is a box-shadow, not an outline.

box-sizing and content

Same declared width and height, different boxes. The panel should report the box-sizing value and the content area that results.

width: 200px; height: 100px; padding: 20px; border: 5px solid #1e3a8a
Expect: box-sizing content-box. Content 200 × 100. Padding 20px. Border 5px. Total 250 × 150. Total is larger than the declared 200 × 100, because padding and border are added outside the content

Inspect this box

box-sizing: border-box; width: 200px; height: 100px; padding: 20px; border: 5px solid #1e3a8a
Expect: box-sizing border-box. Content 150 × 50. Padding 20px. Border 5px. Total 200 × 100. Total matches the declared 200 × 100, because padding and border come out of it

Inspect this box

box-sizing: border-box; width: 20px; height: 20px; padding: 20px; border: 2px solid #1e3a8a
Expect: box-sizing border-box. Content 0 × 0. Padding 20px. Border 2px. Total 44 × 44. Content cannot go below zero, so the box is bigger than the declared 20 × 20

 

padding: 10px; border: 2px solid #1e3a8a; margin: 0 10px
Expect: box-sizing content-box. Padding 10px. Border 2px. Margin 0 10px. Observe: inline element, so width and height do not apply. Content is the size of the text. Vertical padding and border do not push neighbours away

Inline span

padding: 10px; border: 2px solid #1e3a8a; margin: 8px
Expect: box-sizing content-box. Content 100 × 50. Padding 10px. Border 2px. Margin 8px. Total 140 × 90. A replaced element (image). Content is the image size

Grey placeholder

Padding

Four-sided values collapse to CSS shorthand. Zero rows may be hidden or shown as 0. Either is fine, as long as the numbers are right.

width: 100px; height: 40px; padding: 10px
Expect: box-sizing content-box. Content 100 × 40. Padding 10px. Total 120 × 60. All four sides match, so one value

Inspect this box

width: 100px; height: 40px; padding: 18px 24px
Expect: box-sizing content-box. Content 100 × 40. Padding 18px 24px. Total 148 × 76. Sides pair up, so two values

Inspect this box

width: 100px; height: 40px; padding: 1px 2px 3px 4px
Expect: box-sizing content-box. Content 100 × 40. Padding 1px 2px 3px 4px. Total 106 × 44. Nothing pairs up, so four values

Inspect this box

width: 100px; height: 40px; padding: 5px 10px 15px
Expect: box-sizing content-box. Content 100 × 40. Padding 5px 10px 15px 10px. Total 120 × 60. Observe: top and bottom differ but left and right match. The brief mentions only the pair and four-value forms, so check whether this shows as four values

Inspect this box

width: 100px; height: 40px; padding-left: 12px
Expect: box-sizing content-box. Content 100 × 40. Padding 0 0 0 12px. Total 112 × 40. One side only

Inspect this box

width: 100px; height: 40px; padding: 0
Expect: box-sizing content-box. Content 100 × 40. Total 100 × 40. Observe: no padding at all. Check whether the row is hidden or shows 0

Inspect this box

width: 100px; height: 40px; padding: 5%
Expect: box-sizing content-box. Content 100 × 40. Padding 20px. Total 140 × 80. Percentages are resolved to pixels (5% of the 400px wide parent)

Inspect this box

Border

Border widths, per side. A border only takes space when its style is not none.

width: 100px; height: 40px; border: 4px solid #1e3a8a
Expect: box-sizing content-box. Content 100 × 40. Border 4px. Total 108 × 48

Inspect this box

width: 100px; height: 40px; border-style: solid; border-color: #1e3a8a; border-width: 1px 2px 3px 4px
Expect: box-sizing content-box. Content 100 × 40. Border 1px 2px 3px 4px. Total 106 × 44

Inspect this box

width: 100px; height: 40px; border-left: 8px solid #1e3a8a
Expect: box-sizing content-box. Content 100 × 40. Border 0 0 0 8px. Total 108 × 40. One side only

Inspect this box

width: 100px; height: 40px; border: 6px double #1e3a8a
Expect: box-sizing content-box. Content 100 × 40. Border 6px. Total 112 × 52. Double style, still 6px in total

Inspect this box

width: 100px; height: 40px; border: 3px dashed #1e3a8a
Expect: box-sizing content-box. Content 100 × 40. Border 3px. Total 106 × 46. Style should be reported if the panel shows it

Inspect this box

width: 100px; height: 40px; border-width: 5px; border-style: none
Expect: box-sizing content-box. Content 100 × 40. Total 100 × 40. A width with no style takes no space, so the border is 0

Inspect this box

width: 100px; height: 40px; border: thick solid #1e3a8a
Expect: box-sizing content-box. Content 100 × 40. Border 5px. Total 110 × 50. The keyword thick is 5px. thin is 1px and medium is 3px

Inspect this box

width: 100px; height: 40px; border: 4px solid #1e3a8a; border-radius: 12px
Expect: box-sizing content-box. Content 100 × 40. Border 4px. Total 108 × 48. Border radius does not change the numbers

Inspect this box

Outline

Outline sits outside the border and takes no space. The tool draws its own highlight with a box-shadow, so it never covers the page's outline.

width: 100px; height: 40px; outline: 3px solid #b00020
Expect: box-sizing content-box. Content 100 × 40. Outline 3px, offset 0px. Total 100 × 40. Outline takes no space, so Total is just the content

Inspect this box

width: 100px; height: 40px; outline: 2px dashed #b00020; outline-offset: 6px
Expect: box-sizing content-box. Content 100 × 40. Outline 2px, offset 6px. Total 100 × 40

Inspect this box

width: 100px; height: 40px; padding: 10px; outline: 2px solid #b00020; outline-offset: -6px
Expect: box-sizing content-box. Content 100 × 40. Padding 10px. Outline 2px, offset -6px. Total 120 × 60. Negative offset draws the outline inside the border edge

Inspect this box

width: 100px; height: 40px; outline-width: 4px; outline-style: none
Expect: box-sizing content-box. Content 100 × 40. Total 100 × 40. Observe: a width with no style. No outline is drawn, so the row should be hidden or show 0

Inspect this box

width: 100px; height: 40px; border: 2px solid #1e3a8a; outline: 3px solid #b00020
Expect: box-sizing content-box. Content 100 × 40. Border 2px. Outline 3px, offset 0px. Total 104 × 44. Border and outline together. The two should be reported separately

Inspect this box

width: 100px; height: 40px; box-shadow: 0 0 0 4px #f4a300
Expect: box-sizing content-box. Content 100 × 40. Total 100 × 40. Observe: the page's own box-shadow, which is not an outline. Press Esc afterwards. The orange shadow should come back, because the tool restores what it replaced

Inspect this box

Margin

Margin is the outermost layer and counts towards Total.

width: 100px; height: 40px; margin: 20px
Expect: box-sizing content-box. Content 100 × 40. Margin 20px. Total 140 × 80

Inspect this box

width: 100px; height: 40px; margin: 10px 30px
Expect: box-sizing content-box. Content 100 × 40. Margin 10px 30px. Total 160 × 60

Inspect this box

width: 100px; height: 40px; margin: 1px 2px 3px 4px
Expect: box-sizing content-box. Content 100 × 40. Margin 1px 2px 3px 4px. Total 106 × 44

Inspect this box

width: 100px; height: 40px; margin: -10px 0 0 20px
Expect: box-sizing content-box. Content 100 × 40. Margin -10px 0 0 20px. Total 120 × 30. Negative margins are reported with the minus sign. The box overlaps what is above

Inspect this box

width: 200px; height: 40px; margin: 0 auto
Expect: box-sizing content-box. Content 200 × 40. Margin 0 100px. Total 400 × 40. Auto margins are reported as the pixels they resolve to (the 400px parent leaves 200px, shared evenly)

Inspect this box

width: 100px; height: 40px; margin: 0
Expect: box-sizing content-box. Content 100 × 40. Total 100 × 40. Observe: no margin at all. Check whether the row is hidden or shows 0

Inspect this box

Total

Total in these samples is the border box plus margin: content, padding, reserved space and border, then margin. Outline is never counted because it takes no space. If the panel defines Total another way, use the other rows to check the sum.

width: 100px; height: 50px; padding: 10px; border: 2px solid #1e3a8a; margin: 8px
Expect: box-sizing content-box. Content 100 × 50. Padding 10px. Border 2px. Margin 8px. Total 140 × 90. Border box 124 × 74, plus 8px margin on each side

Inspect this box

box-sizing: border-box; width: 160px; height: 80px; padding: 10px; border: 2px solid #1e3a8a; margin: 4px 12px
Expect: box-sizing border-box. Content 136 × 56. Padding 10px. Border 2px. Margin 4px 12px. Total 184 × 88. Border box stays 160 × 80, plus the margins

Inspect this box

width: 100px; height: 50px; padding: 10px; border: 2px solid #1e3a8a; margin: 8px; outline: 6px solid #b00020
Expect: box-sizing content-box. Content 100 × 50. Padding 10px. Border 2px. Outline 6px, offset 0px. Margin 8px. Total 140 × 90. Same as the first sample, so the 6px outline does not change Total

Inspect this box

Reserved space and scrollbar gutter

Space taken by scrollbars, or reserved for them with scrollbar-gutter. The numbers depend on the operating system and its scrollbar setting. Overlay scrollbars, the macOS default, take no space at all, so check what your own machine does.

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow: scroll
Expect: Reserved space 15px on the right and bottom with classic scrollbars (Windows, Linux, macOS set to always show). 0 with macOS overlay scrollbars. Content shrinks by the same amount

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow-y: auto
Expect: Reserved space 15px on the right only, because the text overflows. 0 with overlay scrollbars

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow-x: scroll; overflow-y: hidden
Expect: Reserved space 15px at the bottom only. 0 with overlay scrollbars

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow: auto; height: 220px
Expect: 0. Nothing overflows, so no scrollbar and no space reserved

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow: auto; height: 220px; scrollbar-gutter: stable
Expect: 15px on the right even with no overflow, because the gutter is reserved. 0 with overlay scrollbars

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow: auto; height: 220px; scrollbar-gutter: stable both-edges
Expect: 15px on each side, 30px in all. 0 with overlay scrollbars

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow: scroll; scrollbar-width: none
Expect: 0. The scrollbar is hidden, so it takes no space

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

width: 200px; height: 100px; border: 2px solid #1e3a8a; overflow: scroll; scrollbar-width: thin
Expect: Observe. A thin scrollbar is narrower than 15px. The exact size depends on the browser

Line one
Line two
Line three
Line four
Line five
Line six
Line seven
Line eight

Gap above: positive margins

Gap above is the distance between the bottom edge of the box above and the top edge of the one you click. Sibling margins collapse in normal flow, so two margins do not simply add. In every pair below, click the second box.

neighbour margin-bottom: 30px; target margin-top: 20px
Click the second box. Expect: Gap above 30px (margins collapse to the larger, 30px)

Neighbour above

Target

neighbour margin-bottom: 20px; target margin-top: 30px
Click the second box. Expect: Gap above 30px (margins collapse to the larger, 30px)

Neighbour above

Target

neighbour margin-bottom: 30px; target margin-top: 30px
Click the second box. Expect: Gap above 30px (a tie: both margins are 30px, so the panel has specific wording)

Neighbour above

Target

neighbour margin-bottom: 40px; target margin-top: 10px
Click the second box. Expect: Gap above 40px (margins collapse to the larger, 40px)

Neighbour above

Target

neighbour margin-bottom: 0; target margin-top: 20px
Click the second box. Expect: Gap above 20px (margins collapse to the larger, 20px)

Neighbour above

Target

neighbour margin-bottom: 20px; target margin-top: 0
Click the second box. Expect: Gap above 20px (margins collapse to the larger, 20px)

Neighbour above

Target

neighbour margin-bottom: 0; target margin-top: 0
Click the second box. Expect: Gap above 0. Observe: no gap at all. Check whether the row is hidden or shows 0

Neighbour above

Target

Gap above: negative margins

Two negative margins collapse to the most negative one.

neighbour margin-bottom: -8px; target margin-top: -20px
Click the second box. Expect: Gap above -20px (negative margins collapse to the most negative, -20px)

Neighbour above

Target

neighbour margin-bottom: -20px; target margin-top: -8px
Click the second box. Expect: Gap above -20px (negative margins collapse to the most negative, -20px)

Neighbour above

Target

neighbour margin-bottom: -8px; target margin-top: -8px
Click the second box. Expect: Gap above -8px (a tie: both margins are -8px, so the panel has specific wording)

Neighbour above

Target

Gap above: mixed margins

One positive and one negative margin add together.

neighbour margin-bottom: 30px; target margin-top: -8px
Click the second box. Expect: Gap above 22px (positive and negative margins add: 30px + -8px)

Neighbour above

Target

neighbour margin-bottom: -8px; target margin-top: 30px
Click the second box. Expect: Gap above 22px (positive and negative margins add: 30px + -8px)

Neighbour above

Target

neighbour margin-bottom: 20px; target margin-top: -20px
Click the second box. Expect: Gap above 0 (positive and negative margins add: 20px + -20px). They cancel out, so the boxes touch

Neighbour above

Target

neighbour margin-bottom: 10px; target margin-top: -30px
Click the second box. Expect: Gap above -20px (positive and negative margins add: 10px + -30px)

Neighbour above

Target

Gap above: overlap and the documented limit

A negative gap means the boxes overlap. When the overlap is larger than the neighbour's own height, the target ends up starting above the neighbour's top edge, so the tool shows no gap row. That is the documented limit, not a bug.

neighbour margin-bottom: 0; target margin-top: -20px
Click the second box. Expect: Gap above -20px. Overlap of 20px. The target starts 10px below the neighbour's top edge

Neighbour above

Target

neighbour margin-bottom: 0; target margin-top: -40px; heights 100px and 30px
Click the second box. Expect: Gap above -40px. The neighbour is 100px tall, so the target still starts inside it. A negative gap larger than the target's own height is fine when the neighbour is taller

Neighbour above

Target

neighbour margin-bottom: 0; target margin-top: -30px
Click the second box. Expect: Gap above -30px. Observe: the target starts exactly at the neighbour's top edge, which is the boundary of the limit

Neighbour above

Target

neighbour margin-bottom: 0; target margin-top: -40px
Click the second box. Expect: No Gap above row. The target would start above the neighbour's top edge, which the tool does not treat as a gap by design. Documented limit. Margin of -40px is bigger than the 30px neighbour

Neighbour above

Target

neighbour margin-bottom: -40px; target margin-top: 0
Click the second box. Expect: No Gap above row. The target would start above the neighbour's top edge, which the tool does not treat as a gap by design. Documented limit. Same result when the negative margin is on the neighbour instead

Neighbour above

Target

neighbour margin-bottom: 0; target margin-top: -40px; heights 30px and 100px
Click the second box. Expect: Gap above -40px. Observe: the target is 100px tall and starts 10px above the neighbour's top edge. By the same rule there should be no Gap above row

Neighbour above

Target

Gap above: where margins do not collapse

Flex items and inline-blocks keep their margins separate. A box with nothing above it has no gap row.

neighbour margin-bottom: 30px; target margin-top: 20px; flex column
Click the second box. Expect: Gap above 50px (margins do not collapse here, so they add up)

Neighbour above

Target

neighbour margin-bottom: 0; target margin-top: 0; flex column, gap 12px
Click the second box. Expect: Gap above 12px (margins do not collapse here, so they add up). Only the flex gap separates the boxes

Neighbour above

Target

neighbour margin-bottom: 30px; target margin-top: 20px; target is inline-block
Click the second box. Expect: Gap above 50px (margins do not collapse here, so they add up). Inline-block does not collapse with a block above it

Neighbour above

Target

first child in its container
Click the box. Expect: No Gap above row, because there is nothing above it

Only box

Pointer suppression

While the bookmarklet is active, pointer activation should be suppressed so clicking a control inspects it instead of using it. Try each control with the bookmarklet on, then press Esc and try again.

Link
Expect: Active: the page does not jump and no message appears. After Esc: the message appears

Follow this link

Details toggle
Expect: Active: stays closed. After Esc: opens

Toggle this

The details element opened.

Checkbox and label
Expect: Active: stays unchecked, whether you click the box or the label. After Esc: toggles

Event counter
Expect: Active: every count stays 0, including double-click. After Esc: counts go up

  • mousedown: 0
  • mouseup: 0
  • click: 0
  • dblclick: 0