Accessibility

WCAG 2.2 Accessibility: CSS Best Practices for Inclusive Design

Dmitriy Hulak
Dmitriy Hulak
12 min read0 views

WCAG 2.2 Accessibility: CSS Best Practices for Inclusive Design

Web accessibility isn't optional. It's essential. CSS plays a crucial role in creating accessible experiences that work for everyone, including users with disabilities.

Why Accessibility Matters

  • 15% of the world population has some form of disability
  • Legal requirements in many countries (ADA, Section 508, EAA)
  • Better UX for everyone - accessibility improvements benefit all users
  • SEO benefits - accessible sites rank better

Color Contrast (WCAG 2.2 Level AA)

Minimum Requirements

  • Normal text: 4.5:1 contrast ratio
  • Large text (18pt+): 3:1 contrast ratio
  • UI components: 3:1 contrast ratio
.button {
  background: #0066cc;
  color: #ffffff;
}

.button-bad { background: #7a7a7a; color: #999999; }

Testing Tools

Use our Gradient Generator with built-in contrast checking, or:

  • Chrome DevTools
  • WebAIM Contrast Checker
  • Lighthouse accessibility audit

Focus States

Never remove focus outlines without providing an alternative.

button:focus {
  outline: none;
}

button:focus-visible { outline: 3px solid #0066cc; outline-offset: 2px; }

button:focus-visible { outline: 3px solid #0066cc; outline-offset: 2px; box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.25); }

Motion Preferences

Respect user preferences for reduced motion:

.card {
  transition: transform 0.3s ease;
}

.card:hover { transform: translateY(-4px); }

@media (prefers-reduced-motion: reduce) { .card { transition: none; }

.card:hover { transform: none; } }

Screen Reader Considerations

Visually Hidden but Accessible

.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;
}
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px;
  z-index: 100;
}

.skip-link:focus { top: 0; }

Text Spacing

Users must be able to adjust text spacing without loss of content:

p {
  line-height: 1.5;
  letter-spacing: normal;
  word-spacing: normal;
}

@supports (line-height: 1.5) { p { line-height: max(1.5, 1em); letter-spacing: max(0, 0.12em); word-spacing: max(0, 0.16em); } }

Touch Targets

Minimum 44x44px touch targets:

.button,
.link {
  min-width: 44px;
  min-height: 44px;
  padding: 12px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

Dark Mode Accessibility

body {
  background: #ffffff;
  color: #1a1a1a;
}

@media (prefers-color-scheme: dark) { body { background: #1a1a1a; color: #f5f5f5; } }

@media (forced-colors: active) { .card { border: 1px solid; } }

Common Mistakes to Avoid

  • Don't rely on color alone
  • Don't use fixed pixel fonts
  • Don't autoplay videos or animations
  • Don't hide focus indicators
  • Don't use low contrast combinations
  • Testing Checklist

    • Keyboard navigation works everywhere
    • Focus indicators are visible
    • Color contrast meets WCAG AA
    • Animations respect reduced motion
    • Touch targets are at least 44x44px
    • Text can be resized to 200%
    • Works with screen readers

    Conclusion

    Accessibility is an ongoing process, not a checkbox. Start with these CSS foundations and test with real users and assistive technologies.

    Related posts

    Continue reading on nearby topics.

    WCAG Accessibility Checker and Compliance Testing ToolsWCAG accessibility checker guide: compliance testing tools, contrast validation, keyboard checks, and practical audit workflow.WCAG in the Messy Middle of Real Frontend: What Teams Miss After the AuditA long practical editorial on WCAG in real products: not theory, but the small interface decisions that quietly break accessibility after sprint pressure, rewrites, and content growth.Inset Shadows for Clean NeumorphismDesign neumorphic controls with restrained inset shadows, clear edge contrast, and state transitions that stay accessible.Accessible Loading Animations for Real ProductsDesign loading states that are informative, calm, and accessible with reduced-motion support and semantic status messaging.

    Comments

    0

    Sign in to leave a comment.

    No comments yet. Be the first.