Unit 1: Core CSS Foundations & SyntaxLesson #3 / 8

Lesson 3: The Resilient CSS Box Model & box-sizing

Er. Manoj Kumar — AuthorEr. Manoj KumarLast Updated: 26 Aug, 2026

1. The 4 Layers of the CSS Box Model

Every element rendered on a webpage is a rectangular box comprising four concentric layers:

  • Content: The text, image, or child nodes inside the element.
  • Padding: Transparent inner spacing between the content and the border.
  • Border: The stroke outline wrapping the padding and content.
  • Margin: Transparent outer spacing pushing neighboring element boxes away.
  • HTML5 Web Code (index.html)
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>CSS Box Model Demo</title>
    <style>
    /* Universal Box Sizing Reset */
    *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    }
    body {
    background-color: #17181c;
    color: #ffffff;
    font-family: Arial, sans-serif;
    padding: 30px;
    }
    .box-card {
    width: 320px;
    padding: 24px;
    border: 2px solid #04AA6D;
    margin: 20px auto;
    background-color: #1f2029;
    border-radius: 12px;
    text-align: center;
    }
    </style>
    </head>
    <body>
    <div class="box-card">
    <h3>Standard Box Model</h3>
    <p>Padding: 24px | Border: 2px | Margin: 20px auto</p>
    </div>
    </body>
    </html>

    2. Clockwise Shorthand Sequence

    When declaring padding or margin, values follow standard Top &rarr; Right &rarr; Bottom &rarr; Left (TRBL) clockwise order:

  • 4 Values: padding: 10px 20px 15px 5px; (Top, Right, Bottom, Left)
  • 2 Values: padding: 10px 20px; (Top/Bottom, Left/Right)
  • 1 Value: padding: 16px; (All 4 sides identical)
  • Interactive Knowledge Check

    Test your understanding of Lesson #3 concepts

    Why do modern developers universally set * { box-sizing: border-box; }?