Content
The actual text, image or child layout area. Width and height normally apply here.
The CSS box model explains how every element takes up space: content, padding, border and margin. If you understand this, layout stops feeling random.
.card {
padding: 2rem;
border: 1px solid #263247;
margin-block: 2rem;
}
Box Model
CSS draws each element as a rectangular box. The content box holds text, images or child elements. Padding creates inner breathing room. Border draws the visible edge. Margin pushes other boxes away.
Beginners often see one rectangle on screen and assume one value controls it. In reality, several layers work together. That is why an element can look too wide, too tall or too far away even when the width value seems correct.
The box model is not just theory. It is the foundation behind cards, buttons, forms, dashboards, responsive sections and almost every spacing decision in professional interface work.
The actual text, image or child layout area. Width and height normally apply here.
Inner space between the content and the border. It makes components feel comfortable.
The visible edge around padding and content. It can affect total size.
Outer space between this box and surrounding boxes. It belongs outside the border.
Visual model
Layout debugging becomes much easier when you can point to the exact part of the box that creates the visual result: inner space, outer space, edge, size or overflow behavior.
Outside the element. It separates the element from neighbors.
The visible edge that wraps padding and content.
Internal space that keeps content from touching the edge.
The usable area where text, media and children live.
Examples
.card {
max-width: 36rem;
padding: 1.5rem;
border: 1px solid #263247;
margin-block: 2rem;
}
.card {
width: 600px;
height: 280px;
padding: 60px 12px 8px 43px;
margin-left: 97px;
}
Rules that matter
Box model CSS should make the interface easier to reason about. When a value cannot be explained, it usually becomes a future layout bug.
Use padding for space inside a component and margin for space around it.
DevTools shows content, padding, border and margin separately. Use that view before guessing.
Most content should decide height naturally. Fixed height often creates overflow.
Repeated spacing values make layouts feel intentional instead of improvised.
Cards, buttons and forms need inner spacing; page sections need outer rhythm.
Long labels and translated text expose weak box model decisions quickly.
Production thinking
The box model turns visual spacing into a predictable system. Without it, every card, button and section becomes a pile of magic numbers.
Good box model decisions improve readability, touch targets and focus visibility. Tight boxes make interfaces harder to use.
Production CSS should make spacing decisions visible in code. Use clear padding, margin and sizing rules instead of one-off pixel nudges.
A clean layout helps users stay on the page. Readable, stable content supports engagement and avoids frustrating layout shifts.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, change the lab CSS and inspect the box again.
Senior audit upgrade
Every element has content, padding, border and margin. Spacing bugs often come from confusing internal space with external space.
The actual text, image or child layout area.
Padding creates internal breathing room. Border is the visible edge around it.
Margin pushes other boxes away and can collapse vertically in normal flow.
margin
border
padding
content