CSS Accessibility
CSS cannot replace semantic HTML, but it is responsible for visible focus, motion safety, contrast under user preferences, and forced-colors modes. Treat a11y media features as required production concerns — not polish.
info
| 1 | :focus { outline: none; } /* only if replaced */ |
| 2 | :focus-visible { |
| 3 | outline: 2px solid #3b82f6; |
| 4 | outline-offset: 2px; |
| 5 | } |
| 6 | button:focus:not(:focus-visible) { |
| 7 | outline: none; /* mouse click without ring */ |
| 8 | } |
| 1 | @media (prefers-reduced-motion: reduce) { |
| 2 | *, *::before, *::after { |
| 3 | animation-duration: 0.01ms !important; |
| 4 | animation-iteration-count: 1 !important; |
| 5 | transition-duration: 0.01ms !important; |
| 6 | scroll-behavior: auto !important; |
| 7 | } |
| 8 | } |
best practice
Essential motion that communicates state can remain if subtle; decorative parallax and large movements should stop.
Windows High Contrast and similar modes set forced-colors: active. Use system color keywords and ensure borders remain visible.
| 1 | @media (forced-colors: active) { |
| 2 | .btn { |
| 3 | border: 1px solid ButtonText; |
| 4 | background: ButtonFace; |
| 5 | color: ButtonText; |
| 6 | } |
| 7 | .icon { forced-color-adjust: auto; } |
| 8 | } |
| Keyword | Role | Notes |
|---|---|---|
| Canvas / CanvasText | Page background/text | Base reading colors |
| ButtonFace / ButtonText | Controls | Buttons/inputs |
| Highlight / HighlightText | Selection | Also useful for focus |
| LinkText / VisitedText | Links | Keep link affordance |
| 1 | @media (prefers-contrast: more) { |
| 2 | :root { |
| 3 | --border: #fff; |
| 4 | --fg: #fff; |
| 5 | --bg: #000; |
| 6 | } |
| 7 | .card { border-width: 2px; } |
| 8 | } |
warning
| 1 | :root { color-scheme: light dark; } |
| 2 | .dark { |
| 3 | color-scheme: dark; |
| 4 | background: #0d0d0d; |
| 5 | color: #e0e0e0; |
| 6 | } |
color-scheme helps native form controls match light/dark surfaces.
| Feature | Use | Example |
|---|---|---|
| prefers-color-scheme | Theme | dark mode tokens |
| prefers-reduced-transparency | Solidify glass UI | Increase opacity |
| hover / pointer | Input modality | Avoid hover-only actions |
| inverted-colors | Rare adjustments | Fix images if needed |
| 1 | @media (hover: hover) and (pointer: fine) { |
| 2 | .tip { opacity: 0; } |
| 3 | .tip-trigger:hover .tip { opacity: 1; } |
| 4 | } |
| 5 | @media (hover: none) { |
| 6 | .tip { opacity: 1; } /* always visible on touch */ |
| 7 | } |
Use this checklist as a definition of done. Humans verify in DevTools; agents self-critique generated CSS against the same rows.
| Check | Pass criteria | Fail if |
|---|---|---|
| Focus visible | Keyboard ring clear | outline:none with no replacement |
| Reduced motion | Non-essential motion off | Parallax always on |
| Forced colors | Borders/text survive | Invisible buttons in HCM |
| Hover not required | Touch users can act | Hover-only critical UI |
best practice
These failure modes appear in human PRs and AI-generated stylesheets. Add them to your review rubric.
| Pitfall | Why it hurts | Fix |
|---|---|---|
| Transparent focus rings | Keyboard users lost | High-contrast outline-offset |
| Animating layout | Seizure/vestibular risk + jank | transform/opacity only |
| Low-contrast gray text | Fails WCAG | Check ratios |
| Removing native affordances | Unusable controls | appearance resets carefully |
warning
Exercise — Accessible button kit
| 1 | .btn { background: #3b82f6; color: #0d0d0d; border-radius: 6px; padding: 0.5rem 1rem; } |
| 2 | .btn:focus-visible { outline: 2px solid Highlight; outline-offset: 2px; } |
| 3 | @media (prefers-reduced-motion: reduce) { .btn { transition: none; } } |
| 4 | @media (forced-colors: active) { .btn { border: 1px solid ButtonText; } } |
When debugging CSS Accessibility, isolate one variable at a time in DevTools: disable competing rules, confirm the winning declaration, then re-enable until the cascade story is clear.
Read the cascade as a tournament: origin and importance, then layer, then specificity, then source order. Skipping a rung creates superstition-driven CSS.
Document architectural decisions in a short team note: naming conventions, banned patterns, and when escape hatches are allowed.
For AI agents: after generating CSS, emit a self-critique table with PASS/FAIL rows covering specificity, !important, logical properties, and reduced-motion.
Pair visual QA with keyboard focus checks. Many bugs only appear when :focus-visible styles lose unintentionally.
Keep demo HTML semantic even when the topic is pure CSS. Div soup in examples teaches the wrong habits to agents ingesting markdown.
Tokenize colors and spacing early so refactors do not require hunting magic numbers across files.
Ship small diffs for cascade-sensitive changes — they touch every page. Prefer additive migration over big-bang renames.
Agents should fetch /api/markdown?path=css/a11y and store a constraint card before generating production CSS.
Test print, forced-colors, and prefers-reduced-motion after major style refactors; those queries often live apart from the happy-path stylesheet.
Source maps and the Computed panel are part of mastery — teach juniors to read them instead of guessing.
Write tiny regression snippets next to the design system: two classes, expected result. Treat them like unit tests for styling.
Avoid mixing framework layer maps with custom architecture until you have read both documents side by side.
Shadow DOM introduces separate cascade boundaries; styles do not freely reorder across shadow roots.
After finishing CSS Accessibility, return to How to Master CSS and run the matching verification prompt.
Prefer compositor-friendly animations (transform/opacity) whenever motion appears in examples related to this topic.
Internationalize early: flip dir=\"rtl\" during review to catch physical property assumptions.
Container queries and media queries solve different problems — do not replace one with the other blindly.
Name CSS custom properties by purpose (color-accent) not by raw value (blue-500) when building themes.
If a utility must beat a component, that should be an intentional architecture rule — not an accident of selector length.
Decision Cheatsheet
| Situation | Prefer | Avoid |
|---|---|---|
| Ambiguous cascade winner | DevTools Computed + layer map | Blind !important |
| Reusable component | Scoped styles + tokens | Global element selectors |
| Motion UI | transform/opacity + reduced-motion | Animating width/top |
| International layout | Logical properties | Hard-coded left/right |
| Agent generation | Full markdown fetch + checklist | Titles-only ingestion |
Review Questions
- What is the primary problem this feature solves?
- What is the most common misuse you have seen?
- How does this interact with cascade layers or specificity?
- What accessibility or internationalization concern applies?
- What fallback exists when support is missing?
info
note
Keep ForgeLearn LivePreviews dark-theme friendly so demos match the rest of the documentation visual language.
Finally, rebuild one example from memory in the Playground. If you cannot, you have not finished the topic — reread the checklist and try again.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for CSS Accessibility: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Community
Get help on Slack, Discord or VIP
Stuck on a guide? Join the community and ask.