CHAPTER 04
Beginner
CSS Borders, Margins, Padding, and Box Model
Updated: May 10, 2026
5 min read
# CSS Box Model: Borders, Margins, and Padding
1. Introduction
Every single element on a web page is a rectangular box. The CSS Box Model dictates how these boxes are sized and how they interact with each other. Understanding the box model is the most important step in learning web layout.2. Learning Objectives
- Understand the core Box Model (Content, Padding, Border, Margin).
- Apply margins and padding effectively.
-
Use the
box-sizingproperty to prevent layout breaks.
3. Detailed Explanations
The Box Model Breakdown
- 1. Content: The actual text or image.
- 2. Padding: The space *inside* the border, around the content.
- 3. Border: The wall surrounding the padding and content.
- 4. Margin: The invisible space *outside* the border, pushing other elements away.
Padding and Margins
You can set them on all sides, or individually.
css
Borders and Border Radius
Borders add visual outlines.border-radius rounds the corners.
css
The Magic of box-sizing: border-box
By default, if you set width to 100px, and add 20px padding, the box becomes 140px wide! This breaks layouts. border-box fixes this.
css
4. Mini Project: Profile Card
Let's build a standard UI component using the Box Model.
html
css
5. MCQs
Q1: Which property affects the space OUTSIDE the border of an element? A) Padding B) Margin C) Spacing D) Outline *Answer: B*6. Summary
Mastering the Box Model means you control space. Margins push elements away, padding adds internal breathing room, and borders frame your content. Always usebox-sizing: border-box!