CSS block formatting context 2026-11-05
A CSS block formatting context is a formatting context in which block-level boxes participate in block layout and interact with relevant CSS floats. A box establishing a new context gives its contents an independent layout context. This is distinct from simply being a CSS block container or an ordinary block-level box.[ref]
CSS flow-root, selected by
display: flow-root, explicitly creates a block container establishing a new CSS block formatting context. An ordinary CSS inline-block box similarly combines an inline outer role with an independent flow context for its contents.[ref]A useful controlled layout experiment gives a parent
width: 200px; height: auto; margin: 0; padding: 0; border: 0 and only one child, with float: left; width: 80px; height: 60px; margin: 0. With no other content or constraints, compare ordinary display: block with display: flow-root on the parent. The ordinary parent's content height is zero in this setup; the context-establishing parent's content height includes the sixty-pixel float. The child remains floated in both cases. This is a predicted result of the stated layout rules, rather than a browser timing measurement.[ref]CSS Display Module Level 3 by World Wide Web Consortium. Appendix A, formatting-context examples: containing internal floats
[ref]Margins do not collapse across the context boundary, but eligible margins of sibling blocks inside it can still collapse. For example, adjoining internal bottom/top margins of twenty and thirty CSS pixels can still give a thirty-pixel separation. Establishing a context is therefore not a universal switch disabling CSS margin collapsing.[ref]
CSS Display Module Level 3 by World Wide Web Consortium. Appendix A, margins across formatting-context boundaries
[ref]Finally, CSS flow-root itself does not request clipping or a scrollbar. Treat formatting isolation, CSS containing block geometry and CSS overflow as separate properties of the layout.
CSS clearance 2026-11-05
CSS clearance is the spacing introduced by the
clear rules when a block's border edge must be placed below relevant earlier CSS floats. The calculation considers its hypothetical position and the floats to be cleared. It is a layout effect rather than a replacement for the block's declared margin.[ref]For a simple horizontal-text example, take a left float whose bottom outer edge is at vertical coordinate CSS pixels. A following block would normally have its top border edge at coordinate . With
clear: left and zero vertical margins, the needed displacement ispixels. If a relevant right float instead extends to , clear: both requires the border edge to reach that lower boundary, giving pixels in the same simplified geometry.The relevant edge includes the float's margin geometry; its content height alone is not always the correct reference. Clearing also concerns floats in the applicable CSS block formatting context, rather than every floated element anywhere in the document.
Margins make the general rule subtler. Introducing clearance inhibits the relevant CSS margin collapsing, so one cannot universally calculate it by adding an ordinary positive gap after all margins have already been collapsed. CSS2.2 explicitly permits zero or negative clearance. Its negative-clearance example separates previously collapsing margins and computes the correction needed for the final border-edge position.[ref]
CSS float 2026-11-05
A CSS float is a box shifted toward the left or right under the applicable flow rules, allowing surrounding inline content to wrap beside it. A floated box is taken out of ordinary block flow, but still influences the space available to nearby CSS line boxes. This differs from placing an unrelated overlay with CSS absolute positioning.[ref]
Visual formatting model in CSS 2.2 by W3C. §9.5, Floats
For an illustrative horizontal layout, a container is CSS pixels wide and a left float has width , height , and zero margins, padding and borders. Lines next to the float have pixels of horizontal space, provided no other float or constraint reduces it. Below the float's bottom, a line can again use the full pixels. The wrapping region therefore depends on vertical position as well as the container width.
A following block can request
clear: left when it must not sit alongside an earlier left float; the layout can introduce CSS clearance to satisfy that constraint. This changes placement rather than deleting or resizing the float.[ref]The floated box also establishes a CSS block formatting context for its own contents. Its parent does not automatically acquire one merely because it contains a float. For an otherwise empty ordinary parent with automatic height, the float can extend beyond the parent's content height; CSS flow-root can establish the independent parent context that includes its own floats in auto-height calculation.
CSS flow-root 2026-11-05
CSS flow-root is the
flow-root display value that creates a block container establishing a new CSS block formatting context. It provides an explicit way to isolate the relevant flow-layout interactions without requesting clipping or scrollbars.[ref]A margin example makes the boundary visible. Suppose an ordinary block parent has zero margin, padding and border, automatic height, and one in-flow block child of height CSS pixels. The child has top margin and all other margins zero. Assume no other constraints or clearance. With ordinary
display: block, the child's top margin can collapse through the parent's top; the parent's content height is in this setup. With display: flow-root, the margin does not collapse across that context boundary, so the parent includes the thirty-pixel top margin and twenty-pixel child, giving height .[ref]CSS Display Module Level 3 by World Wide Web Consortium. Appendix A, margins across formatting-context boundaries
[ref]This does not disable every internal instance of CSS margin collapsing. Two eligible sibling blocks inside the new context can still combine adjoining margins of twenty and thirty pixels into thirty. The boundary separates contexts; it does not rewrite all spacing rules within one.
The modern display terminology also separates outer and inner roles.
display: inline-block corresponds to an inline outer role with a flow-root inner role. Thus a CSS inline-block box can sit in a surrounding line while independently formatting its contents.[ref]CSS Display Module Level 3 by World Wide Web Consortium. §2, display summary table
Finally, CSS flow-root is distinct from
overflow: hidden or overflow: clip. Those values concern CSS overflow, with their own clipping and scrolling behavior. Choose an independent flow context for its layout effect rather than treating all these declarations as interchangeable. CSS inline-block box 2026-11-05
A CSS inline-block box participates as one unit in its parent's CSS inline formatting context while providing a CSS block container for its own contents. It can therefore sit beside text or other inline-level boxes while containing independently laid-out text and blocks. The outer and inner layout roles are separate.[ref]
For example, two cards each have a CSS border box width of CSS pixels, zero margins and an intervening space that occupies pixels. Their combined width is pixels. They can share an available line width of pixels, but not pixels under these assumptions. Text inside either card can wrap within that card; the surrounding line treats the card as one unit instead of dividing it into several fragments.
Declaring
display: inline-block; width: 80px also makes width applicable to an ordinary non-replaced element that would otherwise have generated an inline box. Check CSS box-sizing before deciding whether the eighty pixels describe its content or border dimensions.CSS vertical alignment determines placement within the surrounding line. A gap beneath an inline-block can consequently concern baseline alignment rather than a mysterious extra margin. Source whitespace between cards can also occupy inline space. Diagnose these effects using the outer line layout and the card's internal CSS block formatting context separately.
CSS margin collapsing 2026-11-05
CSS margin collapsing combines eligible adjoining vertical margins into one collapsed margin. In the horizontal text layout described by CSS 2.2, this can occur between ordinary in-flow block boxes and in specified parent-child or empty-block situations. It does not mean that every pair of nearby margins is added or collapsed.[ref]
For two eligible sibling blocks, a first block's bottom margin of CSS pixels and the next block's top margin of give a collapsed margin of , not . Positive adjoining margins contribute their largest value.
Negative values make the rule more interesting. For a collapsing group with a positive margin of and a negative margin of , the result is pixels. With only and , it is , not . More generally, take the largest positive value, or zero if none, and subtract the largest absolute negative value, or zero if none.[ref]
Eligibility comes before arithmetic. Horizontal margins do not collapse under these rules, and margins of a CSS inline-block box do not collapse with surrounding boxes or its in-flow children. A parent's top border or padding can prevent the top parent-child collapse that would otherwise occur. Establishing a separate CSS block formatting context also changes the relevant parent-child relationships.[ref]
Box model in CSS 2.2 by W3C. §8.3.1, inline-block and block-formatting-context exclusions and parent-child cases
A useful debugging example is a parent's first child's top margin apparently moving the whole group rather than creating an internal gap. Inspect whether those margins are adjoining before changing unrelated dimensions. The CSS margin box describes a box's margin geometry, while CSS margin collapsing specifies how eligible margins interact during layout.
CSS overflow 2026-11-05
CSS overflow concerns content or painting extending beyond a box's assigned region and the properties controlling its clipping and scrolling. The distinction between the box's size and the extent of its contents is essential: restricting a box does not necessarily make every descendant smaller.[ref]
For example, a zero-padding container has content width CSS pixels, while a child has width pixels and begins at its left edge. The child extends fifty pixels beyond the container. The container's declared width can remain even when more of the child is painted.
With both axes set to
overflow: visible, overflow is not clipped by that property. overflow: hidden clips and does not expose ordinary scrolling controls, but can still permit programmatic scrolling. overflow: clip forbids scrolling altogether and does not create a CSS scroll container. overflow: auto supplies scrolling behavior when needed under its rules.[ref]CSS Overflow Module Level 3 by World Wide Web Consortium. §3.1, visible, hidden, clip and auto definitions
These choices can also affect layout. On an applicable block box, scrollable overflow values establish an independent formatting context. The non-scrollable
clip value alone does not; display: flow-root can separately establish a CSS block formatting context. A request to clip and a request to isolate formatting consequently need not be the same declaration.[ref]CSS Overflow Module Level 3 by World Wide Web Consortium. §3.1, clip versus hidden and independent formatting contexts
CSS overflow does not delete overflowing DOM nodes. Clipped content can still exist in the document, and a scrollbar is not a replacement for checking whether important information remains accessible in the intended medium. Also distinguish a glyph or shadow painting beyond its nominal bounds from a larger scrollable content region; the specification defines ink and scrollable overflow separately.