Mô hình hộp
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
English
Every box has layers
- CSS treats every element as a box.
- Content is your text or image. Padding is space inside, around the content.
- Border is a line around the padding. Margin is space outside, pushing other boxes away.

English
Padding and border
padding: 20px;adds 20 pixels of space inside, on all four sides.border: 2px solid black;draws a line from its width, style and colour. Any order works, but width, style, colour is the usual way to write it.- Padding makes a box feel roomy; a border makes it stand out.
English
<style>
.card {
background-color: #eef;
padding: 16px;
border: 2px solid #88a;
}
</style>
<div class="card">A comfy padded card.</div>
English
Common mistakes
- The box model is content, then padding, then border, then margin (inside to outside).
- Padding adds space inside the border.
English
Now you try
- Padding is inside; the border sits around it.
- Add padding to a box, then a border.
Khám phá
The CSS box model
Every box is content + padding + border + margin around it.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Give the box some breathing room inside. Add padding: 20px; to the .box rule.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Draw a line around the box. Add border: 2px solid navy; to the .box rule — the usual order is width, style, colour.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Style the tip box with both layers: padding: 12px; inside and border: 3px dashed orange; around it.