SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
The Box Model and SizingWriting Modes and Logical PropertiesSizing ElementsBorders and ShadowsDisplay and Document FlowNormal FlowFloats and ColumnsPositioning and StackingStacking and Z-Index Measuring boxes and predicting their positions
Box Model and Flow

The Box Model and Sizing

Predict a box’s border-to-border width from its content, padding, border, and sizing rule.

A card can have a width of 200 pixels in the stylesheet and measure 236 pixels across on the page. To explain the difference, find the edge that the width measures.

Read a box from the inside out

The content box holds the card’s text or image. Padding creates space between that content and the border. If the card has a background color, you can see it behind the padding. The border encloses both regions. Margin creates space outside the border, where the card’s background stops.

To move a label away from the inside edge of a card, increase the padding. To leave space between the outside of the card and its neighbor, look at the margin. The browser inspector’s box-model diagram shows the four regions separately.

Predict the width

For an ordinary block using content-box, the specified width measures the content. Give the card a width of 200 pixels, 16 pixels of padding on each side, and a 2-pixel border on each side. From one border edge to the other, it measures 236 pixels. Both sides count.

With border-box, the same specified width includes the padding and border. The card measures 200 pixels across, leaving 164 pixels for the content. A line of text may wrap sooner even though all three declarations use the same numbers. Margin lies outside both measurements.

With 16px padding and a 2px border per side, content-box gives 200px of content and a 236px border box. Border-box fits 164px of content inside a 200px border box.

Key Takeaways

  • Padding creates room inside the painted box. Margin creates space outside its border.
  • Box sizing tells you which edge to measure before you add or subtract padding and borders.

Try it yourself

Try it yourself

Size the note

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

How is this lesson?

Previous lesson Setting type and color for readable textNext lessonWriting Modes and Logical Properties
Edit on GitHubReport on GitHub
On this page
%

On this page

Read a box from the inside outPredict the widthKey TakeawaysTry it yourself