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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 5 of 50 · css

The Box Model

Duration: 10 mins

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;
}
Previous: The Cascade & SpecificityNext: Box‑Sizing Property