Block Formatting Context
A CSS rule that governs how block-level elements are calculated and positioned relative to each other — essential to understanding layout.
Block formatting context (BFC) is a core concept in the CSS box model. Each BFC is an independent layout universe where block-level elements stack vertically, floats clear, and margins collapse according to specific rules. Without understanding BFC, float clearing, margin collapsing, and z-order often seem surprising.
You create a new BFC with CSS properties like display: flex, display: grid, overflow: hidden, or contain: layout. A BFC isolates layout effects — changes inside don't affect elements outside. It's also the foundation of robust web design: a well-structured BFC hierarchy makes layout predictable and maintainable.