A CSS containing block is the reference rectangle used by applicable layout rules to determine a box's size and position. Which ancestor establishes it, and which edges define it, depend on the positioning and layout context. It is therefore not simply another name for the immediate parent DOM element.[ref][ref]
Consider a horizontal block with
position: relative; width: 300px; padding: 20px; border: 5px solid and content-box sizing. Its content width is and its padding-box width is CSS pixels. An ordinary block child whose width is 50% uses the applicable -pixel content-width reference, giving pixels. A child with position: absolute; width: 50% instead uses this positioned ancestor's padding-box reference, giving pixels. Assume no intervening ancestor establishes another reference, and no child padding, borders or other size constraints.[ref]Visual formatting model details in CSS 2.2 by W3C. §10.1, normal-flow and absolutely positioned containing blocks; §10.2, percentage widths
The same percentage text thus produces different numbers because its geometric reference changes. This is useful when debugging an apparently wrong width: first identify the actual CSS containing block, then apply CSS box-sizing and the remaining constraints.
A CSS containing block does not automatically confine all descendant painting. Content may extend beyond it; CSS overflow and clipping rules are separate. A positioning reference, a clipping boundary and a DOM tree parent need not identify the same rectangle or object.
New to topics? Read the docs here!