Back to blog

CSS Box Model: Border, Padding & Content in Practice

Understanding the box model in 2025 is still the fastest way to debug layout drift and build responsive cards with confidence.

Designer reviewing interface layout sketches beside a laptop.
Photo by Glenn Carstens-Peters on Unsplash

Every element you ship is a box, even if it does not look like one. When layout bugs appear, I inspect padding, border, and content measurements before touching anything else.

A practical trick: define spacing with tokens and visualize the model in devtools. Once designers and engineers share the same vocabulary, pushing changes to production becomes much faster.

.feature-card {
  box-sizing: border-box;
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.feature-card--alert {
  border-color: #c05621;
  padding-inline: calc(1.5rem + 8px);
}

box-sizing: border-box keeps the overall width predictable, while modifiers can adjust padding or border color without changing the underlying footprint.