What Is the Box Model Visualizer?
The Box Model Visualizer is an interactive tool that illustrates the CSS box model — content, padding, border, and margin — in real time. Adjust values and see exactly how each property affects element sizing.
Why Use This Tool?
The CSS box model is one of the most fundamental concepts in web layout, but it trips up developers constantly. Misunderstanding how padding and border affect total element width (especially with different box-sizing values) causes countless layout bugs. This tool makes the relationships visible and intuitive.
How to Use This Box Model Visualizer
- Adjust margin values — Use the Margin slider (0 to 50 px). It sets one value for all four sides, the same as the margin shorthand with a single value. Margin creates space outside the element's border.
- Set border width and style — Set the border thickness (0 to 10 px), pick one of the eight border styles (solid, dashed, dotted, double, groove, ridge, inset, outset) and choose its colour. The border sits between margin and padding.
- Control padding — Use the Padding slider (0 to 60 px, all four sides) to set the space between the border and the content area. Width (0–400 px) and Height (0–300 px) set the declared size.
- Toggle box-sizing — Switch between
content-box(default) andborder-boxto see how each model calculates total element size. - Read the computed dimensions — The visualizer shows the total computed width and height, breaking down how margin, border, and padding contribute to the final size.
Worked example: the readout checked against Chromium
On October 12, 2026 we built the same box in Chromium for each case below and read back its content size, its rendered (border-box) size and the space it took inside a container. All four rows matched the tool's readout to the pixel.
| Settings | box-sizing | Content | Rendered (border box) | Space taken incl. margin |
|---|---|---|---|---|
| 200×120, padding 16, border 2, margin 20 | content-box | 200×120 | 236×156 | 276×196 |
| same | border-box | 164×84 | 200×120 | 240×160 |
| 100×80, padding 60, border 10 | border-box | 0×0 | 140×140 (not 100×80) | 140×140 |
| 60×300, padding 30, border 4, margin 10 | border-box | 0×232 | 68×300 | 88×320 |
- border-box is not a hard limit. When padding plus border is larger than the declared size, the content shrinks to 0 and the box grows to fit them (CSS Box Sizing 3). In row 3, 2 × 60 padding + 2 × 10 border = 140 px, so a box declared 100 × 80 renders 140 × 140. The tool flags this case under the readout.
- One axis can collapse alone. Row 4 has room vertically but not horizontally: the content is 0 px wide and 232 px tall. Text in a box like that wraps one character per line or overflows.
- "Space taken" is for one box on its own. Vertical margins between stacked blocks collapse to the larger of the two (CSS 2.2 section 8.3.1), so two of these boxes stacked sit 20 px apart, not 40. Horizontal margins and margins inside flex or grid containers do not collapse.
- Margin, border and padding are one value for all four sides here, as with the single-value shorthand. Ranges: margin 0–50 px, border 0–10 px, padding 0–60 px, width 0–400 px, height 0–300 px.
- Border style does not change the size. All eight styles take the full border width; double splits it into two lines and a gap, and groove, ridge, inset and outset only change the shading.
Sources
Checked on .
Frequently Asked Questions
Built by Derek Giordano · Part of Ultimate Design Tools