Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Your actual content
Text, images, etc.
The actual content of the element - text, images, or other elements
width: 200px;
height: 100px;Space between content and border - inside the element
padding: 20px;
padding-top: 10px;A line around the padding and content
border: 2px solid black;
border-radius: 10px;Space outside the border - creates distance from other elements
margin: 30px;
margin-left: auto;<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div class="container">
<h2>🎨 Box Model Visualization</h2>
<div style="display: flex; justify-content: center; position: relative;">
<div class="box-demo">
<span class="label margin-label">Margin</span>
<span class="label border-label">Border</span>
<span class="label padding-label">Padding</span>
<div class="box-content">
<strong>Content Area</strong><br>
Your actual content
</div>
</div>
</div>
<div class="info-section">
<div class="info-card margin-card">
<strong>Margin</strong><br>
<small>40px all sides</small>
</div>
<div class="info-card border-card">
<strong>Border</strong><br>
<small>8px solid</small>
</div>
<div class="info-card padding-card">
<strong>Padding</strong><br>
<small>30px all sides</small>
</div>
<div class="info-card content-card">
<strong>Content</strong><br>
<small>300px width</small>
</div>
</div>
</div>
</body>
</html>Loading preview...
width: 200px;
padding: 20px;
border: 5px;
margin: 15px;
Total Width = 200 + (20×2) + (5×2) + (15×2)
= 200 + 40 + 10 + 30
= 280px200px
Content
+ 40px
Padding
+ 10px
Border
+ 30px
Margin
By default, width and height only apply to the content. But you can change this behavior:
box-sizing: content-box; width: 200px; padding: 20px; /* Total width = 240px */
Width applies to content only
box-sizing: border-box; width: 200px; padding: 20px; /* Total width = 200px */
Width includes padding and border
box-sizing: border-box for easier sizing! Many developers apply this to all elements:* { box-sizing: border-box; }