Skip to content

Extend container-query grid to the flexbox grid - #42784

Draft
mdo wants to merge 3 commits into
v6-devfrom
mdo/grid-container-queries
Draft

Extend container-query grid to the flexbox grid#42784
mdo wants to merge 3 commits into
v6-devfrom
mdo/grid-container-queries

Conversation

@mdo

@mdo mdo commented Aug 2, 2026

Copy link
Copy Markdown
Member

Draft — opening this to capture where the container-query grid work stands. dist/ is intentionally not rebuilt here.

Summary

Picks up the CSS Grid container-query work and extends it to the flexbox grid, plus a few things that got tangled up with it.

Both grids are now container-driven. .row joins .grid as a query container (container-type: inline-size), and make-grid-columns() generates .md:col-*, .md:offset-*, .md:row-cols-*, and the .md:g-* gutters with @container instead of @media. A .md:col-6 in a narrow sidebar now splits when the row hits 768px rather than the viewport.

Query containers on body and .container. Gutter classes are set on the .row itself, and an element can never query its own container-type, so the responsive gutter variants were previously dead code. Making <body> (named body) and .container/.container-fluid (named layout) query containers gives them an ancestor to resolve against.

.contains-* renamed to .container-*. New .container-inline / .container-size naming, with a new utilities/container docs page, a sidebar entry, and all the stale .contains-inline references in card, list group, and stepper examples updated.

Spacing scale rework. $spacers and $gutters key 2 becomes .375rem with finer steps through the middle of the range, which ripples through the spacing, margin, and gutter docs.

Docs. Grid and gutter examples switch to ResizableExample with the container-query breakpoint badge, there's a fullscreen grid playground dialog, and the migration guide gains notes for the viewport-to-container change and its containment side effects.

Outstanding todos

Carried over from an adversarial review of this work. None are blockers for reviewing the direction, but they should be resolved before this ships.

  • Decide whether responsive gutters are actually correct. They now resolve, but against the parent (.container or body), not the row they're applied to. .md:g-3 on a nested row keys off whatever ancestor container happens to be nearest, which is a different reference box than the sibling .md:col-* classes on the same row. The alternative is moving gutter declarations onto > * so they resolve against the row like everything else.
  • md: means two things. Grid columns are container-based, but responsive utilities (.md:d-flex, .md:text-center, sticky, display, flex) are still viewport media queries. It's documented in the migration guide and on the new utilities page, but we should decide whether that split is the long-term story.
  • Audit the containment side effects. container-type: inline-size establishes a containing block for position: absolute/fixed descendants and creates a stacking context, and Chrome 129+ deliberately diverges from Safari/Firefox here. Worth checking dropdowns, tooltips, and menus inside rows across the browser matrix. Also: a .row whose inline size depends on its contents can collapse to zero.
  • No fallback for engines without container query support. There's no @supports guard, so unsupported browsers drop every responsive column class and stack completely. Media-query grids degraded far more gracefully. Decide whether we care given the v6 support floor.
  • ResizableExample badge mismeasures flexbox demos. It observes the first child of .bd-resizable-container, which for flexbox examples is .container, not the .row that actually carries container-type. Between container padding and row negative margins it reads roughly one gutter low near each boundary. It should target the nearest descendant with container-type.
  • Confirm the spacing scale change belongs here. The $spacers / $negative-spacers / $gutters rework is global and unrelated to the grid migration. It may deserve its own PR.
  • Consider an opt-out. Right now there's no way to keep media-query grids short of overriding container-type yourself.

Verified locally: css-lint, css-compile, docs-build (no broken links), and docs-lint all pass.

mdo added 3 commits July 17, 2026 11:57
…g scale

Every .row is now a query container alongside .grid, so responsive column,
offset, row-cols, and gutter classes respond to the row's own width instead of
the viewport. Because gutter classes are set on the .row itself and an element
cannot query its own container, the body element and .container/.container-fluid
are now named query containers so a top-level row still resolves against the
page width.

Renames the .contains-* container-type utilities to .container-* and documents
them on a new utilities page, and reworks the spacer and gutter scale so key 2
is .375rem with finer steps through the middle of the range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant