Responsive and accessible styling
Scope: Next.js 16.x candidate, App Router, Cache Components disabled, TypeScript. Source walkthroughs and expected outcomes; no framework build or browser execution has been verified.
What you will learn
- Use logical properties
- Preserve keyboard focus and reduced motion
catalog.module.css — responsive grid
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }.card { padding: 1rem; border: 1px solid #66717e; border-radius: 0.5rem; background: white; }.cover { width: min(100%, 240px); aspect-ratio: 2 / 3; position: relative; }.controls { display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem; }@media (min-width: 720px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }At a 360px viewport the cards stack; at 800px the grid has two columns. Actual rendered dimensions must be checked in a browser.
How it works
The grid starts with one flexible column and adds a second at 720 CSS pixels. minmax(0, 1fr) allows a column to shrink rather than retaining a large intrinsic minimum. Logical properties such as padding-inline follow writing direction. Flexible tracks do not guarantee that their contents fit: test long unbroken names, images and nested controls; use wrapping and sizing rules where needed. At 320 CSS pixels check that ordinary vertical content needs no horizontal scrolling, except content genuinely requiring two-dimensional layout. Also check that sticky headers do not obscure focused controls. Use actual links for destinations, buttons for actions, visible focus, labels and landmarks. If animation is added, honor reduced-motion preferences. An optional CSS-only alternative follows; no motion is required for the core experience.
Optional focus and reduced-motion rules
button:focus-visible { outline: 3px solid #174b81; outline-offset: 3px; }.notice { padding-inline: 1rem; transition: opacity 150ms; }@media (prefers-reduced-motion: reduce) { .notice { transition: none; } }The keyboard focus outline remains visible; the optional transition is removed when reduced motion is requested.
Common mistake
Do not remove the outline to make a focused control look cleaner unless you provide an equally visible replacement. CSS order and source order can also change the visual reading sequence; keep keyboard order meaningful.
Try it yourself
Use the fixture at 320px and 800px in an approved browser. Tab from the skip link to navigation and the filters; record visible focus, overflow and whether each form field has a label.
Further reading
Next lesson: Image component dimensions.