Box model (CSS): plainly explained.

The CSS box model describes every element as content, padding, border and margin. The four layers, content-box versus border-box, and margin collapsing.

Design · Updated Nov 7, 2026

DEFINITION

The CSS box model describes how every element is a box made of content, padding, border and margin, which together define its size and spacing.

CATEGORY

Design

RELATED

Flexbox, CSS Grid

Summarize this page with AI

The CSS box model describes how every element on a page is rendered as a rectangular box, built from four layers: content, padding, border and margin. Together they decide how big an element is and how much space surrounds it, so the box model is the foundation of all CSS layout.

01

The four layers

  • Content: the text or image itself, sized by width and height.
  • Padding: the space between the content and the border, inside the box.
  • Border: the line around the padding.
  • Margin: the space outside the border, separating the element from its neighbours.

You can inspect all four in any browser's dev tools, where the box model diagram shows each layer's pixel value.

02

box-sizing: content-box versus border-box

The box-sizing property decides whether width and height include padding and border. The difference is the single most common source of sizing surprises.

Behaviour
width coverscontent-box (default)Content onlyborder-boxContent + padding + border
200px box + 20px paddingcontent-box (default)Renders 240px wideborder-boxRenders 200px wide
Predictabilitycontent-box (default)Surprisingborder-boxPredictable

Most projects set box-sizing: border-box globally with *, *::before, *::after { box-sizing: border-box; }.

03

Margin collapsing

Vertical margins between two block elements can collapse into a single margin equal to the larger of the two, rather than adding up. It is expected behaviour but often surprising, and it does not happen inside a flex or grid container.

04

Common issues and best practices

Most sizing surprises come from the default content-box behaviour. Set box-sizing: border-box once, use padding for inner space and margin for outer space, and keep values on a consistent scale so spacing stays predictable.

05

The box model and modern layout

Flexbox and grid change how spacing is best handled: their gap property spaces children without the pitfalls of collapsing margins, so reaching for gap instead of per-item margins keeps layouts cleaner and easier to maintain.

06

The box model at BeBranded

At BeBranded we build on a consistent box-sizing base so spacing stays reliable across every screen and component. It is part of the clean, maintainable front-end in our design work.

FAQ

Questions about Box model (CSS).

Another question?

Write to us
What is the CSS box model?
The CSS box model describes every element as a box made of content, padding, border and margin. These four layers define the element's size and the space around it.
What are the parts of the box model?
Content, padding, border and margin. Content is the element itself, padding is inner space, border wraps the padding, and margin is the outer space between elements.
What is box-sizing: border-box?
With border-box, an element's width and height include its padding and border, so the box does not grow unexpectedly. It makes sizing predictable and is the common default in modern CSS.
What is the difference between padding and margin?
Padding is the space inside the border, between the content and the edge of the box. Margin is the space outside the border, separating the element from its neighbours.
Why is my element wider than the width I set?
With the default content-box, padding and border are added on top of the width, making the box larger. Setting box-sizing: border-box includes them in the width and fixes this.
How does Webflow handle the box model?
Webflow exposes padding, border and margin visually in the Designer's style panel and uses border-box sizing, so what you set matches the rendered box.

Related

Related terms, and where to go next.

BeBranded
UX/UI

html.to.design: import any website into Figma

html.to.design converts any website into an editable Figma design. Benchmarks, redesigns, and HTML capture for AI-assisted development.

Read the article
Illustration for the article “What a Webflow designer does beyond visual design”
Development

What a Webflow designer does beyond visual design

Learn what a Webflow designer does beyond visual design, from CMS planning and SEO setup to conversion strategy and project handoff.

Read the article
How to compare web design packages beyond the page count
Design

How to compare web design packages beyond the page count

Compare web design packages by scope, SEO, CMS, support and ownership, not page count. Use a practical framework before you sign.

Read the article

Let’s talk

Tell us what you want to build.

Thirty minutes with the people who will work on your project. You leave with a clear view of the scope, the timeline and the next steps.

What happens next

  1. 1A 30-minute callWe listen to your goals, your constraints and your context.
  2. 2A clear scopeWe map what is worth doing first, and what it takes.
  3. 3A costed proposalYou decide, with no commitment and no sales pitch.