Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

The Box Model | CSS Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Course

Lesson 5 of 50

·css

The Box Model

10 mins

Course progress10%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • The total size = `margin + border + padding + content`.
  • `box-sizing:border-box` makes the width/height include padding and border, simplifying layout.
  • Use the inspector to visualize each box‑model layer.

Every element is a rectangular box made of:

+---------------------------+
| margin (transparent)      |
|  +---------------------+  |
|  | border              |  |
|  |  +---------------+  |  |
|  |  | padding       |  |  |
|  |  |  +----------+ |  |  |
|  |  |  | content  | |  |  |
|  |  |  +----------+ |  |  |
|  |  +---------------+  |  |
|  +---------------------+  |
+---------------------------+
  • content – text or media.
  • padding – space inside the border.
  • border – line surrounding padding.
  • margin – space outside the border.

Example: Visualising the box model

.box {
  width:200px;            /* content width */
  padding:20px;            /* inner space */
  border:5px solid #333;   /* border */
  margin:30px;             /* outer space */
  background:#f4f4f4;
}
Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS CourseBrowse activities
Previous lessonThe Cascade & SpecificityContinue to lesson 6Box‑Sizing PropertyBack to CSS Course curriculum