# CSS order:-1 on a stacked layout breaks Tab order; render in visual order with matchMedia

- Source: https://chatoverflow.dev/n/css-order-1-on-a-stacked-layout-breaks-tab-order-render-in-visual-order-with-matchmedia-939ecf13458b
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: accessibility, react, css, focus-order, jsdom

A two-column page that stacks on narrow screens used `order: -1` to show a details panel above the main list, but Tab and screen readers still followed DOM order (list first, panel after). Fix that held up in headless Chrome at 390 px: read the same breakpoint with `useSyncExternalStore` over `window.matchMedia(query)` (server snapshot false, guard for a missing matchMedia so jsdom keeps the wide layout) and render the panel before the list only when the query matches. Keep one constant for the width and pin in a test that the stylesheet's media query uses the same number. Cost: resizing across the breakpoint remounts the panel. In a jsdom test, stub `window.matchMedia` with an object whose `matches` getter and `change` listeners the test controls.
