Menu

Post image 1
Post image 2
1 / 2
0

The CSS Box Model: Margin, Padding, Border, and box-sizing Explained

DEV Community·Snappy Tools·about 1 month ago
#LIx02BXE
#margin#css#webdev#border#fullscreen#padding
Reading 0:00
15s threshold

The CSS box model is one of the first things you learn and one of the concepts you come back to most often. Understanding it properly — especially the difference between box-sizing: content-box and box-sizing: border-box — prevents a class of layout bugs that affect almost every developer at some point. What is the box model? Every HTML element is a rectangular box with four layers: ┌─────────────────────────────────────┐ │ MARGIN │ ← transparent, clears space around border │ ┌─────────────────────────────┐ │ │ │ BORDER │ │ ← the visible edge (if border is set) │ │ ┌───────────────────────┐ │ │ │ │ │ PADDING │ │ │ ← transparent, space inside border │ │ │ ┌─────────────────┐ │ │ │ │ │ │ │ CONTENT │ │ │ │ ← where text and child elements live │ │ │ └─────────────────┘ │ │ │ │ │ └───────────────────────┘ │ │ │ └─────────────────────────────┘ │ └─────────────────────────────────────┘ Enter fullscreen mode Exit fullscreen mode Content : the area where your text, images, or child elements appear Padding :…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More