Cyber Code Academy
Tutorials Academy Courses
Home / CSS / CSS Box Model

CSS Box Model

The four parts

The CSS box model consists of content, padding, border, and margin.

.card {
  width: 320px;
  padding: 20px;
  border: 2px solid #cbd5e1;
  margin: 16px;
  box-sizing: border-box;
}

*, *::before, *::after { box-sizing: border-box; }

With border-box, the declared width includes content, padding, and border. Margins remain outside the box.

Practice

Make two cards with consistent widths and spacing. Compare their dimensions with and without border-box.

Want to learn this professionally?

Explore practical IT training at Cyber Code Academy.

View Academy Courses