Presets
Margin
Padding
Box Model
Live Preview
Content
CSS Output
How to Use the CSS Spacing Generator
- Choose a preset or set your own values.
- Select a unit — px, rem, em, or %.
- Adjust margin and padding per side using sliders or number inputs.
- Enable “Link all sides” to set all four sides at once.
- Watch the box model diagram and live preview update instantly.
- Pick Shorthand or Longhand output, then click Copy CSS.
Box Model Quick Reference
| Layer | Purpose |
|---|---|
| Margin | Space outside the element border |
| Border | The element’s border (set separately) |
| Padding | Space inside the border, around the content |
| Content | The actual content area (text, images, etc.) |
CSS Shorthand Rules
CSS uses a clockwise order: top → right → bottom → left.
/* 1 value: all sides equal */
margin: 16px;
/* 2 values: top/bottom left/right */
padding: 12px 24px;
/* 3 values: top left/right bottom */
margin: 8px 16px 24px;
/* 4 values: top right bottom left */
padding: 8px 16px 12px 16px;
Related Tools
- CSS Flexbox Generator — Build flexbox layouts visually with live output.
- CSS Box Shadow Generator — Design layered shadows with real-time preview.
- CSS Variables Generator — Define and export custom property systems.
