Spacing and Padding Visualizer
See how per-side margin, padding and border change a CSS box. Compare content-box and border-box sizing, then download the CSS.
Measure CSS Margin, Border and Padding
Use one to four values in CSS shorthand order. Four values run top, right, bottom and left.
- Margin
- Border
- Padding
- Content
- Content box
- 136 × 72 px
- Border box
- 174 × 98 px
- With margins
- 210 × 122 px
Spacing and Padding Visualizer: how to use it
- Enter width and height. Use one to four pixel values for margin, padding and border widths.
- Compare the colored layers and the content, border and margin-box measurements. Switch Box sizing to see which measurements change.
- Copy the CSS or download spacing-box.css. Apply the rule to a box in your layout and check its dimensions.
Limits and notes
Runs in your browser. Width is 16–480 px, height is 16–240 px and each spacing value is a nonnegative whole number from 0–48 px. The preview isolates one box and shows physical sides.
How your privacy works →Spacing and Padding Visualizer: common questions
What are the four shorthand positions?
Enter top, right, bottom and left. Two values set top and bottom first, then left and right.
Does margin count toward border-box width?
No. Margins sit outside the border box. Border-box sizing counts the content, padding and border in the specified width when they fit.
What happens if the padding and borders exceed the width?
The content width reaches zero. The border box can still grow beyond the specified width to fit the padding and borders.