CSS Box Model: Complete Guide to Content, Padding, Border & Margin

Learn the CSS Box Model in detail. Understand content, padding, border, margin, box-sizing, width, height, overflow, and practical examples for responsive web design.

CSS Box Model

The CSS Box Model is one of the most important concepts in CSS. It explains how the browser calculates the size of an HTML element and how that element takes up space on a web page.

Every visible HTML element is treated by the browser as a rectangular box. This includes headings, paragraphs, images, buttons, links, forms, sections, <div> elements, and many other elements.

The box model consists of four main parts:

  1. Content
  2. Padding
  3. Border
  4. Margin

Understanding these four areas makes it much easier to control spacing, sizing, alignment, and layout.


What Is the CSS Box Model?

The CSS Box Model describes the structure of an element from the inside out.

A simple way to remember it is:

Content → Padding → Border → Margin

The content is at the center. Padding surrounds the content. The border surrounds the padding. Margin creates space outside the border.

Conceptually, the structure looks like this:

+---------------------------------------+
|                Margin                 |
|   +-------------------------------+   |
|   |             Border            |   |
|   |   +-----------------------+   |   |
|   |   |       Padding         |   |   |
|   |   |   +---------------+   |   |   |
|   |   |   |    Content    |   |   |   |
|   |   |   +---------------+   |   |   |
|   |   +-----------------------+   |   |
|   +-------------------------------+   |
+---------------------------------------+

The browser uses these layers to determine how much space an element occupies.


The Four Parts of the Box Model

1. Content

The content area contains the actual content of an element.

For example, in a paragraph:

<p>Hello World</p>

The words Hello World are part of the content.

For an image, the image itself occupies the content area. For a form input, the text entered into the field is part of its content.

You can specify the content dimensions using properties such as:

width: 300px;
height: 150px;

However, the meaning of width and height depends on the box-sizing property.


2. Padding

Padding is the space between the content and the border.

For example:

.card {
  padding: 20px;
}

This creates 20 pixels of space around the content.

Padding is useful when you want to make content more comfortable to read or prevent text from touching the border.

For example:

.card {
  width: 300px;
  padding: 20px;
  border: 1px solid #ccc;
}

Padding is part of the element’s box. It does not create space outside the element in the same way that margin does.


3. Border

The border surrounds the padding and content.

A border can be added using:

.card {
  border: 2px solid black;
}

A border has three main components:

  • Border width
  • Border style
  • Border color

For example:

.card {
  border-width: 2px;
  border-style: solid;
  border-color: black;
}

The shorthand version is usually more convenient:

.card {
  border: 2px solid black;
}

Borders can also be applied to individual sides:

.card {
  border-top: 2px solid black;
  border-right: 1px solid gray;
  border-bottom: 2px solid black;
  border-left: 1px solid gray;
}


4. Margin

Margin is the space outside an element’s border.

For example:

.card {
  margin: 20px;
}

This creates 20 pixels of outer space around the element.

Margin is commonly used to separate elements from one another.

For example:

h2 {
  margin-bottom: 16px;
}

p {
  margin-bottom: 20px;
}

Unlike padding, margin does not provide space inside the element.

A useful distinction is:

Padding creates internal space. Margin creates external space.


A Simple Box Model Example

Consider this CSS:

.box {
  width: 300px;
  padding: 20px;
  border: 5px solid black;
  margin: 30px;
}

With the default box-sizing: content-box, the declared width of 300px applies only to the content area.

Therefore:

Content width = 300px
Left padding = 20px
Right padding = 20px
Left border = 5px
Right border = 5px

The total width of the element itself is:

300 + 20 + 20 + 5 + 5 = 350px

The margin is outside that 350px.

If there is 30px of margin on both sides, the total horizontal space consumed for layout can be:

30 + 350 + 30 = 410px

This is one of the most common sources of confusion when learning CSS.


The box-sizing Property

The box-sizing property controls how the browser calculates an element’s declared width and height.

The two commonly used values are:

box-sizing: content-box;

and:

box-sizing: border-box;


content-box

content-box is the traditional default value for most elements.

With:

.box {
  width: 300px;
  padding: 20px;
  border: 5px solid black;
  box-sizing: content-box;
}

The 300px width applies to the content only.

The actual border-box width becomes:

300 + 20 + 20 + 5 + 5 = 350px

So the visible box is 350px wide.


border-box

With:

.box {
  width: 300px;
  padding: 20px;
  border: 5px solid black;
  box-sizing: border-box;
}

The declared 300px includes:

  • Content
  • Left and right padding
  • Left and right border

Therefore, the outer width remains 300px.

The content area becomes smaller because padding and borders must fit inside the declared width.

This behavior is often easier to manage in responsive layouts.


Why border-box Is Popular

Many developers use this rule:

*,
*::before,
*::after {
  box-sizing: border-box;
}

It makes width calculations more predictable.

For example:

.container {
  width: 100%;
  padding: 20px;
}

With border-box, the padding is included within the 100% width rather than being added outside it.

This can help prevent unexpected horizontal overflow.


Content Width vs Border-Box Width

It is important to distinguish between different dimensions.

With:

.box {
  width: 300px;
  padding: 20px;
  border: 5px solid;
}

and content-box:

Content width:      300px
Padding:             40px total
Border:              10px total
--------------------------------
Border-box width:   350px

With border-box:

Border-box width:   300px
Padding:             40px total
Border:              10px total
Content width:      250px

The same CSS width can therefore produce different content dimensions depending on box-sizing.


Width and the Box Model

The width property does not always mean “the complete width of the element.”

For example:

.box {
  width: 400px;
}

With the default content-box, the width refers to the content area.

With:

.box {
  width: 400px;
  box-sizing: border-box;
}

the width includes the content, padding, and border.

This distinction is especially important when building columns, cards, navigation bars, forms, and responsive interfaces.


Height and the Box Model

The same concept applies to height.

For example:

.box {
  height: 200px;
  padding: 20px;
  border: 5px solid;
}

With content-box, the total height is:

200 + 20 + 20 + 5 + 5 = 250px

With border-box, the total border-box height remains:

200px

The content area is reduced to accommodate padding and borders.


Padding Shorthand

Padding can be written in several ways.

One value

padding: 20px;

All four sides receive 20px.

Two values

padding: 10px 20px;

The first value applies to the top and bottom.

The second value applies to the left and right.

Three values

padding: 10px 20px 30px;

The values represent:

top:    10px
right:  20px
bottom: 30px
left:   20px

Four values

padding: 10px 20px 30px 40px;

The order is:

top → right → bottom → left

A useful memory trick is TRBL:

Top, Right, Bottom, Left.


Individual Padding Properties

You can also specify each side separately:

padding-top: 10px;
padding-right: 20px;
padding-bottom: 30px;
padding-left: 40px;

This can be useful when different sides need different spacing.

CSS also provides logical padding properties, such as:

padding-block: 20px;
padding-inline: 30px;

Logical properties are useful for layouts that need to work with different writing directions.


Margin Shorthand

Margin follows the same shorthand pattern.

One value:

margin: 20px;

Two values:

margin: 10px 20px;

Three values:

margin: 10px 20px 30px;

Four values:

margin: 10px 20px 30px 40px;

The order is:

top → right → bottom → left


Auto Margins

The auto value can be useful for horizontal alignment.

For example:

.container {
  width: 800px;
  margin-left: auto;
  margin-right: auto;
}

When there is enough available horizontal space, the browser distributes the remaining space between the left and right margins.

A common shorthand is:

.container {
  width: 800px;
  margin: 0 auto;
}

This is a traditional way to center a fixed-width block.

However, modern layouts often use Flexbox or Grid for more complex alignment.


Margin Collapse

One important CSS behavior is margin collapsing.

In certain block formatting situations, the vertical margins of adjacent block elements can collapse into a single margin instead of being added together.

For example:

.first {
  margin-bottom: 30px;
}

.second {
  margin-top: 20px;
}

You might expect 50px between the elements, but in a normal block layout, those adjacent vertical margins can collapse to the larger value, which is 30px.

Margin collapsing has specific rules and does not happen in every layout situation.

For example, margins generally do not collapse between flex items or grid items.

Understanding this behavior can prevent surprising spacing problems.


Negative Margins

Margins can have negative values:

.box {
  margin-top: -20px;
}

A negative margin can cause an element to move closer to or overlap another element.

Negative margins can be useful in some layouts, but they should be used carefully because excessive use can make a layout difficult to understand and maintain.


Borders and Their Effect on Size

Borders add to an element’s dimensions when box-sizing is content-box.

For example:

.box {
  width: 200px;
  border: 10px solid;
}

The content width is 200px, while the border-box width is:

200 + 10 + 10 = 220px

With:

box-sizing: border-box;

the complete width remains 200px.


Border Radius

The border-radius property rounds the corners of an element.

For example:

.card {
  border: 1px solid #ccc;
  border-radius: 12px;
}

Border radius changes the shape of the border’s corners but does not create additional margin.

It is commonly used for cards, buttons, images, inputs, and containers.


Outline Is Different From Border

An outline can look similar to a border, but it is not part of the CSS box model in the same way.

For example:

button {
  outline: 2px solid blue;
}

An outline is drawn around an element and generally does not affect the element’s layout dimensions.

This makes outlines particularly useful for focus indicators.

For accessibility, avoid removing focus indicators unless you provide a clear alternative.


The box-shadow Property

A box shadow can visually extend beyond an element:

.card {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

A shadow is a visual effect. It does not normally increase the element’s layout size.

This is different from padding and borders, which can affect the dimensions of the box depending on box-sizing.


min-width and max-width

CSS also provides minimum and maximum size constraints.

For example:

.card {
  width: 100%;
  max-width: 500px;
}

This allows the element to shrink on smaller screens while preventing it from becoming wider than 500px.

Similarly:

.box {
  min-width: 200px;
}

prevents the element from becoming narrower than the specified minimum under normal sizing rules.

These properties are particularly useful for responsive designs.


min-height and max-height

The same idea applies vertically:

.box {
  min-height: 200px;
  max-height: 500px;
}

If content becomes larger than a constrained height, you may need to control overflow.

For example:

.box {
  max-height: 300px;
  overflow: auto;
}

This can provide scrolling when the content exceeds the available space.


The overflow Property

When content does not fit inside an element’s box, the overflow property controls what happens.

Common values include:

overflow: visible;
overflow: hidden;
overflow: scroll;
overflow: auto;

For example:

.card {
  width: 300px;
  height: 200px;
  overflow: auto;
}

The browser can provide scrolling when the content exceeds the available area.

The related properties are:

overflow-x: auto;
overflow-y: auto;

These allow horizontal and vertical overflow to be controlled independently.


Box Model and display

The box model interacts with the element’s display type.

Common display values include:

display: block;
display: inline;
display: inline-block;
display: flex;
display: grid;

Block-level elements generally participate in block layout and accept width, height, padding, and margins in ways that differ from inline-level elements.

Inline elements have special sizing behavior. For example, width and height generally do not apply to a normal inline box in the same way they do to a block or inline-block box.

If you need an inline element to accept explicit width and height, you can use:

display: inline-block;


Box Model and Flexbox

Flexbox creates a layout context where elements are treated as flex items.

For example:

.container {
  display: flex;
  gap: 20px;
}

Flexbox can control the size and position of child elements.

The gap property is often preferable to adding margins between flex items because it expresses the spacing between items directly.

For example:

.container {
  display: flex;
  gap: 16px;
}


Box Model and CSS Grid

CSS Grid also uses boxes for its grid items.

For example:

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

Each grid item has its own content, padding, border, and margin.

The gap property controls the space between grid tracks without requiring margins on individual items.


Percentage Widths and the Box Model

Consider:

.container {
  width: 100%;
  padding: 20px;
}

With content-box, the content width is 100% and the padding is added around it. Depending on the containing block and surrounding conditions, this can cause the resulting box to exceed the available width.

Using:

.container {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

makes the declared width include the padding and border.

This is one reason border-box is convenient for responsive layouts.


The box-sizing Inheritance Pattern

A commonly used CSS pattern is:

html {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

This establishes border-box at the root and allows all elements and pseudo-elements to inherit it.

Another simpler approach is:

*,
*::before,
*::after {
  box-sizing: border-box;
}

Both patterns are commonly seen in CSS projects.


Pseudo-Elements and the Box Model

Pseudo-elements such as:

::before
::after

can also have dimensions, padding, borders, and other box-model properties.

For example:

.card::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
}

If you apply a global box-sizing rule, including pseudo-elements is often useful:

*,
*::before,
*::after {
  box-sizing: border-box;
}


Replaced Elements

Some HTML elements are known as replaced elements. Examples include:

<img>
<input>
<video>
<iframe>

Their dimensions can behave differently from ordinary elements because their content is supplied by an external resource or user-agent-defined rendering.

For images, a common responsive rule is:

img {
  max-width: 100%;
  height: auto;
}

This helps images shrink to fit within their containing box while preserving their aspect ratio.


The aspect-ratio Property

Modern CSS provides the aspect-ratio property:

.card {
  width: 100%;
  aspect-ratio: 16 / 9;
}

This allows the browser to maintain a preferred width-to-height ratio.

It is useful for:

  • Images
  • Video containers
  • Cards
  • Thumbnails
  • Responsive media components

The property works together with the element’s normal sizing and box model.


Logical Box Model Properties

Modern CSS provides logical properties that describe dimensions according to the writing mode rather than assuming left and right.

Examples include:

margin-inline: auto;
padding-inline: 20px;
padding-block: 10px;
border-inline: 1px solid;

Traditional properties include:

margin-left
margin-right
padding-left
padding-right

Logical properties are especially useful for multilingual interfaces and layouts that may use different writing directions.


The Difference Between Margin and Padding

A common beginner question is whether to use margin or padding.

Use padding when you want to create space inside an element.

.card {
  padding: 20px;
}

Use margin when you want to create space outside an element.

.card {
  margin: 20px;
}

For example, if text is too close to the edge of a card, use padding.

If two cards are too close to each other, margin or the parent’s gap may be appropriate.


The Difference Between Width and Available Space

A width does not always mean the same thing as the amount of space available to an element.

For example:

.box {
  width: 50%;
}

The percentage is generally calculated relative to the relevant containing block.

If the element also has padding and a border, the final dimensions depend on its box-sizing and layout context.

This is why seemingly simple calculations can sometimes produce unexpected results.


calc() and the Box Model

The calc() function can combine different CSS units.

For example:

.box {
  width: calc(100% - 40px);
}

This can be useful when designing flexible layouts.

However, when padding and borders are involved, box-sizing: border-box can often make the sizing model easier to reason about.


CSS Units and the Box Model

Box-model properties can use many CSS units.

Common units include:

px
%
em
rem
vw
vh

For example:

.card {
  padding: 1rem;
  margin: 2rem;
  width: 80%;
}

Fixed units such as px can be useful for precise dimensions, while relative units such as %, rem, vw, and vh can help create flexible layouts.


Box Model Example With a Card

Consider:

<div class="card">
  <h2>CSS Box Model</h2>
  <p>Understanding CSS becomes easier when you understand how boxes work.</p>
</div>

CSS:

.card {
  width: 320px;
  padding: 24px;
  border: 2px solid #ccc;
  margin: 20px;
  box-sizing: border-box;
}

Here:

  • width controls the border-box width.
  • padding creates internal space.
  • border surrounds the padding.
  • margin creates external space.
  • box-sizing: border-box keeps the complete width at 320px.

This is a practical example of the box model in everyday web design.


Box Model Example With content-box

.box {
  width: 300px;
  padding: 25px;
  border: 5px solid black;
  box-sizing: content-box;
}

Total width:

300 + 25 + 25 + 5 + 5
= 360px

The declared width is 300px, but the border-box width is 360px.


Box Model Example With border-box

.box {
  width: 300px;
  padding: 25px;
  border: 5px solid black;
  box-sizing: border-box;
}

Total border-box width:

300px

The content area becomes:

300 - 25 - 25 - 5 - 5
= 240px

This demonstrates the key difference between the two sizing models.


How to Calculate the Total Width

For an element using content-box, the horizontal border-box size can be calculated as:

content width
+ left padding
+ right padding
+ left border
+ right border

For example:

Width = 400px
Padding left/right = 20px
Border left/right = 2px

Then:

400 + 20 + 20 + 2 + 2
= 444px

Margins are outside this calculation.

If you want the total occupied horizontal space including margins, add the left and right margins as well.


How to Calculate the Total Height

For content-box:

content height
+ top padding
+ bottom padding
+ top border
+ bottom border

For example:

Height = 200px
Padding top/bottom = 15px
Border top/bottom = 3px

Then:

200 + 15 + 15 + 3 + 3
= 236px

Again, margins are outside this calculation.


The Box Model and box-shadow

Suppose you have:

.card {
  width: 300px;
  padding: 20px;
  border: 1px solid;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}

The shadow may visually extend beyond the element, but it does not normally increase the element’s layout dimensions.

This is important when comparing what you see on screen with what the browser considers the element’s layout box.


The Box Model and outline

Similarly:

button:focus {
  outline: 3px solid;
}

The outline is drawn outside the border area and generally does not change the layout size.

This makes outlines useful for focus states.


How to Inspect the Box Model

Browser developer tools provide a visual representation of the box model.

In most modern browsers:

  1. Open Developer Tools.
  2. Select an HTML element.
  3. Open the Elements or Inspector panel.
  4. Look at the Styles or Computed section.
  5. Find the box model diagram.

The browser can show:

  • Content dimensions
  • Padding
  • Border
  • Margin

This is one of the fastest ways to diagnose spacing and sizing problems.


Common CSS Box Model Problems

Unexpected element width

You may write:

.box {
  width: 100%;
  padding: 20px;
}

and discover that the box causes horizontal overflow.

A common solution is:

.box {
  box-sizing: border-box;
}


Text touches the border

If content is too close to the edge:

.card {
  padding: 20px;
}


Elements are too close together

Use margin or layout spacing:

.card {
  margin-bottom: 20px;
}

Or, when using Flexbox or Grid:

.container {
  gap: 20px;
}


Fixed height causes content problems

Avoid unnecessary fixed heights such as:

.card {
  height: 100px;
}

If the content can vary, a minimum height may be more appropriate:

.card {
  min-height: 100px;
}

Or allow the content to determine the height naturally.


Unexpected horizontal scrolling

Horizontal overflow can be caused by:

  • An element wider than its container
  • Padding added outside a percentage width
  • Large fixed-width elements
  • Long unbreakable content
  • Images that cannot shrink
  • Negative positioning or margins
  • Layout calculations that exceed the viewport

Using box-sizing: border-box, responsive widths, and appropriate overflow handling can solve many of these issues.


Common Box Model Mistakes

Mistake 1: Assuming width includes padding

With:

.box {
  width: 300px;
  padding: 20px;
}

the default content-box model means the actual border-box width is larger than 300px.


Mistake 2: Confusing margin with padding

Padding affects internal space.

Margin affects external space.

They are not interchangeable.


Mistake 3: Forgetting borders

Borders can increase the final size when using content-box.

For example:

width: 300px;
border: 10px solid;

does not produce a 300px border-box under content-box.


Mistake 4: Using fixed heights unnecessarily

A fixed height can cause text to overflow when content becomes larger.

Whenever possible, allow the browser to determine the height naturally or use min-height.


Mistake 5: Using margins when gap is more appropriate

For Flexbox and Grid layouts, gap often provides cleaner and more predictable spacing between items.

.container {
  display: flex;
  gap: 20px;
}


Best Practices for the CSS Box Model

A few practices can make CSS easier to manage.

Use border-box for predictable sizing

A common global rule is:

*,
*::before,
*::after {
  box-sizing: border-box;
}

Use padding for internal spacing

If content needs breathing room inside a component, use padding.

Use margin or gap for external spacing

Use margin when appropriate, and prefer gap for spacing between Flexbox and Grid items.

Avoid unnecessary fixed heights

Let content determine height whenever possible.

Use responsive sizing

Prefer flexible values where appropriate:

width: 100%;
max-width: 600px;

Inspect elements with developer tools

The browser’s box-model inspector can quickly reveal where unexpected space is coming from.

Think from the inside out

When debugging an element, check:

Content
↓
Padding
↓
Border
↓
Margin

This simple method often makes spacing problems much easier to identify.


CSS Box Model vs box-sizing

These two concepts are closely related but are not the same.

The CSS Box Model describes the different areas surrounding an element:

Content
Padding
Border
Margin

The box-sizing property determines how the declared width and height are interpreted relative to those areas.

For example:

box-sizing: content-box;

means the declared width and height normally refer to the content box.

While:

box-sizing: border-box;

means the declared width and height include the padding and border.


Quick Comparison

PropertyPurpose
widthControls the width according to box-sizing
heightControls the height according to box-sizing
paddingCreates space inside the border
borderSurrounds the padding and content
marginCreates space outside the border
box-sizingControls how width and height are calculated
min-widthSets a minimum width constraint
max-widthSets a maximum width constraint
min-heightSets a minimum height constraint
max-heightSets a maximum height constraint
overflowControls content that exceeds the box
outlineDraws an outline without normally affecting layout
box-shadowAdds a visual shadow without normally affecting layout
gapCreates spacing between Flexbox or Grid items

A Practical Complete Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS Box Model</title>

  <style>
    *,
    *::before,
    *::after {
      box-sizing: border-box;
    }

    body {
      margin: 0;
      font-family: Arial, sans-serif;
    }

    .container {
      width: 100%;
      max-width: 900px;
      margin: 0 auto;
      padding: 20px;
    }

    .cards {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 20px;
    }

    .card {
      width: 100%;
      padding: 24px;
      border: 1px solid #ccc;
      border-radius: 12px;
    }

    .card h2 {
      margin-top: 0;
      margin-bottom: 12px;
    }

    .card p {
      margin: 0;
    }
  </style>
</head>

<body>

  <main class="container">
    <div class="cards">

      <article class="card">
        <h2>First Card</h2>
        <p>This card demonstrates content, padding, border, and margin.</p>
      </article>

      <article class="card">
        <h2>Second Card</h2>
        <p>The border-box model makes width calculations easier to manage.</p>
      </article>

    </div>
  </main>

</body>
</html>

This example demonstrates several useful box-model concepts:

  • Global border-box
  • Responsive width
  • Maximum width
  • Centered container
  • Padding
  • Borders
  • Border radius
  • Grid spacing
  • Natural content height

A Simple Way to Remember the Box Model

Think about a package.

The content is the item inside the package.

The padding is the empty space protecting the item inside the package.

The border is the edge of the package.

The margin is the empty space between this package and other packages.

In CSS:

┌──────────────────────────────┐
│            Margin            │
│  ┌────────────────────────┐  │
│  │         Border         │  │
│  │  ┌──────────────────┐  │  │
│  │  │     Padding      │  │  │
│  │  │  ┌────────────┐  │  │  │
│  │  │  │  Content   │  │  │  │
│  │  │  └────────────┘  │  │  │
│  │  └──────────────────┘  │  │
│  └────────────────────────┘  │
└──────────────────────────────┘

Once this structure becomes familiar, many CSS layout problems become much easier to understand.


Why the CSS Box Model Matters

The CSS Box Model is not just a theoretical concept. It affects almost every visual element on a web page.

It determines:

  • How large an element becomes
  • How much space appears inside an element
  • How much space appears outside it
  • How borders affect dimensions
  • How width and height are calculated
  • How elements fit into responsive layouts
  • Why unexpected horizontal scrolling occurs
  • How cards, buttons, forms, images, and containers are sized
  • How Flexbox and Grid items occupy space

A strong understanding of the box model provides a foundation for learning more advanced CSS topics such as Flexbox, CSS Grid, responsive design, positioning, and component-based layouts.


Final Takeaway

The CSS Box Model describes every element as a box made up of content, padding, border, and margin.

The most important ideas to remember are:

Content = actual content
Padding = space inside the element
Border = edge surrounding the content and padding
Margin = space outside the element

Also remember the difference between:

box-sizing: content-box;

and:

box-sizing: border-box;

With content-box, the declared width and height normally apply to the content area, so padding and borders are added to the final size.

With border-box, the declared width and height include the padding and border, making element sizing more predictable.

A commonly used starting point is:

*,
*::before,
*::after {
  box-sizing: border-box;
}

Once you understand how these boxes are calculated and how they interact with layout systems, CSS becomes much more predictable. Instead of guessing why an element is too large, too small, too close, or overflowing, you can look at each part of the box model and identify exactly where the space is coming from.

Scroll to Top