On this page
  1. Box Model & Sizing
  2. Contents
  3. box-sizing: border-box
  4. Logical Properties & Intrinsic Sizing
  5. aspect-ratio & overflow

Box Model & Sizing

Prev: properties | Up: properties | Next: Display & Layout
Rel: Box Model & Formatting Contexts, Math & Sizing Functions
Ref: MDN Web Docs — CSS Box Model
Tags: #public #web #css #properties #box-model


Contents


box-sizing: border-box

By default (content-box), width and height exclude padding and borders. Setting border-box makes declared dimensions include padding and borders for predictable layouts:

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

Logical Properties & Intrinsic Sizing

Prefer logical properties (inline = text flow axis, block = perpendicular axis) over physical left/right/top/bottom so layouts adapt automatically to RTL or vertical writing modes:

.panel {
  inline-size: min(100%, 65ch);
  margin-inline: auto;
  padding-block: 1rem;
  padding-inline: 1.5rem;
}

aspect-ratio & overflow

.video-box {
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

Linked from

Related notes