Skip to content
Back to Concepts
CSS UniverseTrack 7: Responsive ArchitectureAccessibility in CSS (a11y)
Responsive Architecture · Track 7Core Concept 28

Accessibility in CSS (a11y)

Building accessible websites isn't just empathy—it's good engineering and law (WCAG 2.2). Master the superpower of :focus-visible, calculate mathematical color contrast ratios, and master the bulletproof .sr-only pattern.

1. The Keyboard Warrior: :focus vs. :focus-visible

The Old IssueThe :focus Pseudo-Class

Whenever a user clicks a button with a mouse, :focus applies. Designers hated the blue halo on mouse clicks and rashly wrote outline: none;, making the site unusable for blind/motor-impaired users navigating with keyboard Tab keys!

The Modern StandardThe :focus-visible Pseudo-Class

:focus-visible only activates when the browser detects keyboard navigation (pressing Tab or Arrow keys)! Mouse clicks remain clean, while keyboard users get bright, glowing navigation rings.

button:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 4px;
}

2. The Bulletproof .sr-only Pattern (Screen Reader Only)

Never use display: none or visibility: hidden to hide visual icons. Screen readers completely drop elements with display: none from the accessibility accessibility tree! Use this standard 7-line utility instead:

.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
border: 0;
}

3. Interactive Studio: Live Focus Ring & Contrast Analyzer

Background Lightness95%
Text Lightness20%
WCAG 2.2 Contrast Ratio4.00 : 1
Normal Text (Requires 4.5:1): FAIL
Large Text 18pt+ (Requires 3.0:1): PASS

Accessibility Verification

Legibility allows users in bright sunlight, on low-end screens, or with visual impairments to consume your interface without squinting.

First-Year Student Traps: Accessibility

  • 1.Relying Exclusively on Color for Error States: If an invalid input field only turns red without an error text icon or message, the 8% of male users with red-green colorblindness will have no idea why their form won't submit! Always pair color with an icon and clear message.
  • 2.Ignoring Reduced Motion Preferences: Excessive parallax scrolling or bouncing hero animations can trigger genuine vertigo and nausea in users with vestibular disorders. Always wrap intense animations in @media (prefers-reduced-motion: no-preference)!
Next Masterclass

Print Stylesheets & Clean PDF Generation

Format invoices and receipts for physical paper with @media print, page breaks, and @page margins.

Continue to Concept 29