πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
Search courses…
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Accessible CSS

Web Styles🟒 Free Lesson

Advertisement

Accessible CSS

Focus styles, contrast, reduced motion, and screen reader support.

Overview

Accessible CSS ensures content is usable by everyone.

Key Concepts

  • Focus Styles β€” Visible focus indicators
  • Color Contrast β€” Readable text
  • Reduced Motion β€” Respect user preferences
  • Screen Reader β€” Visually hidden content
  • Skip Links β€” Navigation shortcuts

Code Examples

/* Focus styles */
:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--primary);
  color: white;
  padding: 0.5rem 1rem;
  z-index: 1000;
}

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

/* Visually hidden */
.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;
}

/* Reduced motion */
@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;
  }
}

/* High contrast */
@media (prefers-contrast: high) {
  :root {
    --text: #000000;
    --bg: #ffffff;
    --primary: #0000ff;
  }
  
  .border {
    border: 2px solid #000000;
  }
}

/* Color contrast */
.text-contrast {
  color: #333333; /* 12.6:1 contrast on white */
  background: #ffffff;
}

/* Focus within */
.form-group:focus-within {
  border-color: var(--primary);
}

/* Touch targets */
.button {
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 1rem;
}

/* Readable line lengths */
.prose {
  max-width: 65ch;
  line-height: 1.6;
}

/* Print styles */
@media print {
  .no-print {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    color: #000;
    background: #fff;
  }
  
  a {
    color: #000;
    text-decoration: underline;
  }
}

/* Dark mode accessibility */
@media (prefers-color-scheme: dark) {
  :root {
    --text: #e0e0e0;
    --bg: #121212;
  }
  
  .contrast-warning {
    color: #ffff00; /* High contrast yellow */
  }
}

Practice

Audit a website for accessibility and fix CSS issues.

⭐

Premium Content

Accessible CSS

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
πŸ’ΌInterview Prep
πŸ“œCertificates
🀝Community Access

Already a member? Log in

Need Expert Web Development Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement