Box model

The properties that set an element's size, its inner and outer spacing, and how it clips content that overflows. Borders live under Color, backgrounds & borders.

display

Sets the outer role (how the box takes part in its parent's layout) and the inner layout mode (how its own children are laid out).

ValueEffect
blockGenerates a block box on its own line.
inlineFlows inline with text; width/height and vertical margin do not apply.
inline-blockFlows inline but accepts width, height and all margins.
flex / inline-flexEstablishes a flex container.
grid / inline-gridEstablishes a grid container.
flow-rootA block that establishes a new block-formatting context (clears floats).
contentsThe box disappears; its children take its place in the layout.
noneRemoves the element and its descendants from the layout entirely.

Two-value syntax states outer and inner explicitly, e.g. display: inline flex .

box-sizing

Chooses what width and height refer to.

ValueMeaning
content-boxThe default. Width/height set the content box; padding and border add on top.
border-boxWidth/height include padding and border, so the box never outgrows its declared size.
*, *::before, *::after { box-sizing: border-box; }
The common reset: size every box including its padding and border.

width, height

The size of the content box (or the border box under border-box ). Take a <length> or <percentage> of the containing block, or a keyword: auto (size to content/available space), min-content , max-content and fit-content() .

min-width, max-width, min-height, max-height

Clamp the used size. A max-* wins over width / height , and a min-* wins over both — so a min-* will always be respected. max-width: none and max-height: none remove an upper limit.

aspect-ratio

Holds a preferred width-to-height ratio when only one axis is sized, e.g. aspect-ratio: 16 / 9 . Use aspect-ratio: 1 for a square. Combine with auto to fall back to a replaced element's natural ratio.

margin & longhands

Transparent space outside the border. The shorthand takes one to four values (top, right, bottom, left); the longhands are margin-top , margin-right , margin-bottom and margin-left (plus the logical margin-block / margin-inline ).

margin: auto on a sized block centres it in the inline axis; in a flex or grid item an auto margin absorbs free space on that side. Adjacent vertical margins collapse to the larger of the two.

padding & longhands

Space inside the border, between the border and the content. One to four values, or the longhands padding-toppadding-left . Percentages resolve against the containing block's width on every side. Padding is never negative and never collapses.

overflow, overflow-x, overflow-y

What happens when content is larger than its box.

ValueMeaning
visibleThe default. Content spills outside the box.
hiddenOverflow is clipped; no scrollbars, but scrollable programmatically.
clipOverflow is clipped with no scrolling at all.
scrollAlways shows scrollbars.
autoScrollbars appear only when needed.

Setting any non- visible value establishes a scroll container and a new block-formatting context.

visibility

hidden hides the box but keeps its space in the layout; collapse additionally removes rows/columns from a table; visible is the default.