Visualize the CSS Box Model

Interactively visualize the CSS box model with live padding, border, margin, and content editing.

Interactively visualize the CSS box model with live editing of padding, border, margin, and content dimensions. Toggle between content-box and border-box sizing to see how dimensions change. Use preset layouts for cards, buttons, and hero sections. See computed sizes at every layer, preview the real element, and copy the generated CSS. Everything runs in your browser with zero server calls.

Your data stays in your browser
Was this tool useful?
Tutorial

How to Use

1
1

Adjust Values

Edit padding, border, margin, and content dimensions using the number inputs. The SVG diagram updates in real time.

2
2

Toggle Box Sizing

Switch between content-box and border-box to see how width and height are interpreted differently by each model.

3
3

Copy and Use

Review computed dimensions at each layer, check the live preview, and copy the generated CSS directly into your project.

Guide

Complete Guide to the CSS Box Model

The Four Layers

Every element has content (the text or child elements), padding (transparent space inside the border), border (a visible edge), and margin (transparent space outside the border). Understanding these layers is essential for CSS layout.

Content-Box vs Border-Box

The default content-box model means width and height apply only to the content area. Border-box includes padding and border in the declared width and height, which is generally more intuitive for layout work.

Margin Collapse

Adjacent vertical margins of block-level elements collapse: only the larger margin applies. This behavior surprises many developers. Padding, border, inline elements, and flexbox containers prevent collapsing.

Box Model in Flexbox and Grid

In flexbox and grid layouts, the box model still applies to each item. The flex or grid container controls item placement while each item's box model determines its internal dimensions and spacing.

Examples

Worked Examples

Example: Content-Box Total Width

Given: width 200px, padding 20px each side, border 2px each side, margin 10px each side, box-sizing content-box.

1

Step 1: Content width = 200px (declared width).

2

Step 2: Add padding: 200 + 20 + 20 = 240px.

3

Step 3: Add border: 240 + 2 + 2 = 244px.

4

Step 4: Add margin: 244 + 10 + 10 = 264px total space.

Result: The element renders at 244px wide and occupies 264px total horizontal space.

Example: Border-Box Comparison

Same values but with box-sizing border-box.

1

Step 1: Declared width 200px now includes padding and border.

2

Step 2: Content width = 200 - 20 - 20 - 2 - 2 = 156px.

3

Step 3: Rendered width stays at 200px (padding and border are inside).

4

Step 4: Add margin: 200 + 10 + 10 = 220px total space.

Result: Border-box makes the element 200px wide regardless of padding and border. Total space is 220px.

Use Cases

Use Cases

Learn Box Model Basics

New to CSS? Edit each layer and watch the diagram change to build an intuitive understanding of how content, padding, border, and margin interact to form element dimensions.

Debug Layout Issues

Paste your current CSS values into the tool to see the total space an element occupies. Toggle box-sizing to understand why your element is wider than expected.

Prototype Component Spacing

Use presets like Card or Button as starting points, then tweak padding and margin values until the spacing looks right. Copy the CSS directly into your stylesheet.

Frequently Asked Questions

?What is the CSS box model?

Every HTML element is a rectangular box with four layers: content, padding, border, and margin. The box model defines how these layers combine to determine the element's total size.

?What is the difference between content-box and border-box?

In content-box, width and height set the content area only. In border-box, width and height include padding and border, making layout calculations simpler.

?Which box-sizing should I use?

Most modern CSS resets use border-box for all elements. It makes responsive layouts easier because percentage widths include padding and border.

?Does margin affect element size?

No. Margin creates space outside the border and does not change the element's rendered size. However, it affects the total space the element occupies in the layout.

?What is margin collapse?

When two vertical margins meet, they collapse into a single margin equal to the larger of the two. This only happens vertically and only with block-level elements.

?Is my data private when using this tool?

Completely. All calculations and rendering happen in your browser. No data is sent to any server.

?Is this tool free to use?

Yes. Fully free with no sign-up, no limits, and no ads.

?Can I use negative margins?

The visualizer uses non-negative values for clarity. In real CSS, negative margins are valid and pull elements closer or overlap them.

Help us improve

How do you like this tool?

Every tool on Kitmul is built from real user requests. Your rating and suggestions help us fix bugs, add missing features and build the tools you actually need.

Rate this tool

Tap a star to tell us how useful this tool was for you.

Suggest an improvement or report a bug

Missing a feature? Found a bug? Have an idea? Tell us and we'll look into it.

Related Tools

Recommended Reading

Recommended Books on CSS and Web Design

As an Amazon Associate we earn from qualifying purchases.

Boost Your Capabilities

Recommended Products for Web Development

As an Amazon Associate we earn from qualifying purchases.

Newsletter

Get Free Productivity Tips & New Tools First

Join makers and developers who care about privacy. Every issue: new tool drops, productivity hacks, and insider updates — no spam, ever.

Priority access to new tools
Unsubscribe anytime, no questions asked