CSS Layout Properties: Display, Position, Flexbox and Grid (2026)
How display, position, flexbox and grid really behave, with six common layout bugs reproduced and measured in Chromium 141: fixed elements that scroll away, sticky headers that never stick, a z-index of 9999 that loses, and columns that refuse to share space.
Display: Block, Inline, Flex and Grid
The display value decides how an element takes part in layout. Block elements start on a new line and take the full width; inline elements flow inside text and ignore width and height: we gave a <span> a width of 300 px and it rendered 37 px wide, the width of its text. inline-block flows like text but accepts a size; flex and grid turn an element into a layout container for its children.
Six Layout Gotchas, Measured
Most layout bugs come from a few rules that are easy to miss. We reproduced six in Chromium 141 and measured the result:
| Setup | What happened | Fix |
|---|---|---|
position: fixed inside a parent with transform | After scrolling 500 px it sat at top -300 px and scrolled away; a normal fixed element stayed at 0 | A transform (also filter, perspective or contain) makes the parent the containing block; move the fixed element outside it |
position: sticky inside an overflow: hidden ancestor | Scrolled to -100 px instead of sticking at 0 like the same element in a normal parent | Remove the overflow on ancestors, or use overflow: clip, which does not create a scroll container |
z-index: 9999 on a child of a parent with opacity: 0.99 | A sibling with z-index: 1 still covered it | Opacity below 1 creates a stacking context; set the z-index on the parent instead |
Width on an inline <span> | Ignored (37 px instead of 300) | Use display: inline-block or block |
Grid 1fr 1fr 1fr with one long unbreakable word | Columns of 49 px / 503 px / 49 px | minmax(0, 1fr) plus overflow-wrap: anywhere gave 200 px / 200 px / 200 px |
Two flex: 1 items, one holding a long nowrap label | Widths 8 px / 293 px: the label refused to shrink | min-width: 0 (and an ellipsis) gave 150 px / 150 px |
The last two share a cause: grid tracks sized with fr and flex items both default to a minimum size of "auto", meaning their content's minimum width, so one long word or URL can break an even layout. Setting that minimum to zero lets the space be shared as written.
The Five Position Values
static: the default, in normal flow;topand friends do nothing.relative: offset from its normal spot, while its original space stays reserved.absolute: out of flow, placed against the nearest ancestor that is positioned (anything but static) or that has a transform, filter, perspective or containment.fixed: placed against the viewport, unless an ancestor has one of those same properties, as the first gotcha shows.sticky: acts relative until its scroll container reaches the offset, then sticks; it needs atop(or other inset) and a scroll container that actually scrolls.
Flexbox or Grid
Use flexbox for one direction at a time, such as a toolbar, a row of tags or a vertically centered card body, and grid when rows and columns both matter, such as page layouts, galleries and forms. They combine well: grid for the page, flex inside its cells. Both support gap. Try them hands-on in the Flexbox Playground and the Grid Generator; our CSS Grid guide goes deeper on grid.
Newer Layout Tools and Support
| Feature | Chrome | Firefox | Safari |
|---|---|---|---|
Flexbox gap | 84 | 63 | 14.1 |
aspect-ratio | 88 | 89 | 15 |
Container queries (@container) | 105 | 110 | 16 |
| Subgrid | 117 | 71 | 16 |
Anchor positioning (anchor-name) | 125 | 147 | 26 |
Versions are from MDN's browser-compat-data 8.1.3; anchor positioning was rechecked live through the MDN connector on October 14, 2026, which lists Firefox 147 (January 2026) and Safari 26 (September 2025), so all three major engines now support it.
- [1]W3C, CSS Positioned Layout Module Level 3 (containing blocks, sticky) ↗
- [2]W3C, CSS Transforms Module Level 1: transformed elements establish a containing block for fixed descendants ↗
- [3]MDN, Stacking context (what creates one) ↗
- [4]W3C, CSS Grid Layout Module Level 2: minmax() and automatic minimum size ↗
- [5]MDN browser-compat-data 8.1.3 and live check of anchor-name, Oct 14, 2026 ↗