CSS Accessibility

๐ŸŽจ CSS3+ ๐ŸŸข Chapter 46 of 49 ๐Ÿ“‚ Phase 17: Accessibility & Performance ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Color Contrast ยท Focus Visibility ยท Keyboard Nav ยท Reduced Motion ยท Text Resizing ยท Line Length ยท Touch Targets ยท Color-Only Meaning ยท Screen Readers ยท High Contrast ยท sr-only
Welcome to Chapter 46: CSS Accessibility โ€” part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
๐Ÿ“š What You Will Learn
  • WCAG color contrast requirements and testing tools
  • Focus-visible styling for keyboard navigation
  • prefers-reduced-motion, prefers-contrast media queries
  • Touch target sizing and readable typography
  • Screen reader-only content with .sr-only utility
๐Ÿ’ก Why This Matters

Accessibility is not optional โ€” legal requirement in many countries (ADA, EAA), and 15%+ users have disabilities. CSS plays a critical role: contrast, focus rings, motion sensitivity, text sizing. Accessible CSS is professional CSS.

1Color Contrast & Avoiding Color-Only Meaning
LevelNormal TextLarge Text (18px+)
WCAG AA4.5:1 ratio3:1 ratio
WCAG AAA7:1 ratio4.5:1 ratio
CSS โ€” Accessible Colorsโ–ถ Try in Editor
:root {
  --text-primary: #111827;    /* on white: 16.6:1 โœ… */
  --text-secondary: #4b5563;  /* on white: 7.5:1 โœ… AAA */
  --color-error: #b91c1c;     /* on white: 5.9:1 โœ… */
  --color-success: #15803d;   /* on white: 4.6:1 โœ… */
}

.error-msg {
  color: var(--color-error);
  font-weight: 600;
}
.error-msg::before {
  content: "โš  ";
}
/* Icon + text โ€” not color alone */

DevTools โ†’ Elements โ†’ color picker shows contrast ratio. WebAIM Contrast Checker online tool kuda use cheyandi.

2Focus Visibility & Keyboard Navigation
CSS โ€” Focus Stylesโ–ถ Try in Editor
/* NEVER do this without replacement */
/* *:focus { outline: none; } โŒ */

:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

.btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.2);
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  padding: 12px 20px;
  background: #2563eb;
  color: #fff;
  z-index: 9999;
  border-radius: 0 0 8px 8px;
}

.skip-link:focus {
  top: 0;
}
Property / SelectorExplanation
:focus-visibleKeyboard focus ki matrame ring โ€” mouse click ki ledu
outline-offsetRing element border nundi gap โ€” clearer visibility
.skip-linkKeyboard users main content ki skip cheyadaniki
3prefers-reduced-motion & Touch Targets
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --text-primary: #000000;
    --border-color: #000000;
  }
  .btn { border: 2px solid currentColor; }
}

/* Minimum 44x44px touch targets (WCAG 2.5.5) */
.nav-link, .btn, input[type="checkbox"] {
  min-height: 44px;
  min-width: 44px;
}
4Screen Reader Content & Readable Typography
CSS โ€” .sr-only Utilityโ–ถ Try in Editor
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.prose {
  max-width: 65ch;
  font-size: clamp(1rem, 2.5vw, 1.125rem);
  line-height: 1.7;
}

.sr-only โ€” visually hidden but screen readers read cheyochu. Icon buttons ki accessible label provide cheyadaniki essential.

โš ๏ธ Common Mistakes
  • outline: none on all elements โ€” keyboard users lost
  • Red/green only for error/success โ€” colorblind users fail
  • Auto-playing animations ignoring prefers-reduced-motion
  • Touch targets below 44px on mobile
  • display:none on content that screen readers should read
โ“ Mini Quiz

Q1 WCAG AA normal text contrast ratio entha?

Minimum 4.5:1 contrast ratio between text and background.

Q2 .sr-only vs display:none difference enti?

sr-only visually hides but screen readers access cheyochu. display:none completely removes from accessibility tree.

โœ… Quick Recap
  • 4.5:1 contrast minimum for body text (WCAG AA)
  • :focus-visible for keyboard focus โ€” never remove outline without replacement
  • prefers-reduced-motion: disable/simplify animations
  • 44px minimum touch targets on mobile
  • .sr-only for screen-reader-only accessible labels
  • Never convey meaning through color alone
OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy ยท CSS Complete Roadmap ยท Last updated August 2026