Skip to content

Chapter 7 of 7

Pitfalls, Accessibility, and the Future

Several pitfalls recur across flex and grid. As noted earlier, flex and grid items have an implicit \(min-width: auto\) (or \(min-height: auto\)) that prevents them from shrinking below their content size, causing overflow; the fix is to set \(min-width: 0\) on the item, or \(minmax(0, 1fr)\) on the track. Images in flex containers without \(max-width: 100%; height: auto;\) can blow out their parent. \(overflow: hidden\) on a flex parent can clip absolutely-positioned children unintentionally. Sticky elements inside grid cells require a parent of definite height for the stickiness to fire.\()\)

Accessibility deserves special attention. Both \(order\) (flex) and visual \(grid-area\) reassignment change only the rendering, not the DOM. Screen readers and keyboard tab order follow source order regardless of visual order, so non-cosmetic reshuffling with these properties creates a disconnect between what users see and what assistive technology traverses. When the visual order matters for comprehension, restructure the DOM rather than relying on visual overrides. \(display: contents\) similarly removes a box from the accessibility tree in some older screen readers; modern engines are improving this but verification is wise. On the upside, defining grid tracks and using \(aspect-ratio\) on images prevents most of the layout shift that hurts Cumulative Layout Shift scores, because content reserves space before it loads.

For older browsers, Grid has a clear story: a legacy, partially-implemented version exists in IE10 and IE11 with a different specification, so the modern grid should be wrapped in \(@supports (display: grid) { ... }\). Flexbox works in all modern browsers and even IE11 (with quirks); old \(-ms\)-\) prefixes are rarely needed today. Looking forward, subgrid is now available across recent versions of Chrome, Safari, and Firefox and lets nested grids inherit track sizes from their parent — eliminating a long-standing pain point where inner items couldn't align cleanly to outer columns without redundant declarations. Native CSS masonry via \(grid-template-rows: masonry;\) is being standardized and partially implemented in Firefox. The View Transitions API works across flex and grid for animated DOM changes. For day-to-day work the guidance remains: reach for Grid when structure is two-dimensional and known, Flexbox for one-dimensional component internals, and remember that DOM order is sacred even when visual order seems to need adjusting.

For deeper study, CSS-Tricks' "A Complete Guide to Flexbox" and "A Complete Guide to Grid" remain definitive references, and tools like cssgrid-generator.netlify.app plus the Chrome and Firefox DevTools grid and flex inspectors make iterating on track and alignment values far easier than reading back from rendered pixels. Newer selectors like \(:has()\) and \(:where()\) reshape how layout-adjacent styling can be written, but the grid-versus-flex decision itself rarely changes: it is still mostly about whether you are laying out along one axis or two.

All chapters
  1. 1The Fundamental Decision
  2. 2Flexbox Deep Dive
  3. 3CSS Grid Deep Dive
  4. 4Alignment and Centering
  5. 5Common Layout Patterns
  6. 6Responsive Design and Modern Queries
  7. 7Pitfalls, Accessibility, and the Future

Drill it

Reading is not remembering. These come from the CSS Grid Vs Flexbox When To Use Which deck:

Q

One-line summary: when Grid vs Flexbox?

Grid: 2D layout (rows AND columns), known structure.Flexbox: 1D layout (row OR column), content-driven.

Q

Center a single element on the page — Grid or Flex?

Either works. display: grid; place-items: center; or display: flex; align-items: center; justify-content: center;

Q

Make a sidebar + main layout with Grid?

grid-template-columns: 250px 1fr;

Q

Same layout with Flex?

display:flex; with sidebar flex: 0 0 250px and main flex: 1.