Back to CSS Universe

foundation

Box Model

Visualize content, padding, border, and margin with live adjustments.

layoutbox-modelvisualizer

Learning checklist

  • content/padding/border/margin
  • box-sizing and overflow
  • Nested box composition

Definition

Visualize content, padding, border, and margin with live adjustments.

Syntax

content/padding/border/margin

Example

Use the visualizer below to apply these properties and see the result live.

Deep dive

Why this matters

Principles, mental models, and debugging clues tailored to the topic.

Visual intuition

Each property is paired with motion or color feedback so you build muscle memory, not just recall syntax.

Copy-ready CSS

Controls emit exact CSS you can copy. Use it as a starter token or paste into DevTools for instant validation.

Performance notes

Learn where reflow, repaint, or compositing occurs so you avoid jank and choose GPU-friendly paths.

Accessibility first

Focus-visible, reduced-motion, and contrast tips are woven into every lab to keep experiences inclusive.

Practice

Try recreating a UI card using this topic. Toggle between dark and light modes to validate token contrast and responsiveness.

Tip: use DevTools overlays (grid/flex) plus the copy CSS button.

Interactive Lab

Box Model Visualizer

Adjust padding, border, and margin to see how total box size changes. Toggle box-sizing to compare content-box vs border-box.

margin (20px)
padding (18px)
content area

Border-box keeps width/height stable by subtracting padding and border from the declared size.

.box { margin: 20px; padding: 18px; border: 4px solid rgba(99, 102, 241, 0.8); border-radius: 16px; box-sizing: border-box; }

Related topics

Keep exploring adjacent concepts.

foundation

Flexbox Visualizer

Interactive flex playground for axes, alignment, wrapping, and gaps.

View page

intermediate

Grid Visualizer

Design explicit and implicit grids with repeat(), minmax(), and auto-fit/auto-fill.

View page

foundation

Typography Lab

Experiment with font-size, line-height, letter-spacing, and rhythm.

View page