light-dark-mode

Enforce WCAG-compliant color contrast across light, dark, and forced-color modes.

39|2|Updated Mar 28, 2026
One-click install
npx skills add https://github.com/mgifford/accessibility-skills --skill light-dark-mode
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: light-dark-mode
Source: https://github.com/mgifford/accessibility-skills/tree/main/skills/light-dark-mode
Command: npx skills add https://github.com/mgifford/accessibility-skills --skill light-dark-mode

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Projects often ship interfaces that fail to adapt to light and dark themes, reducing readability and accessibility. This Skill provides a principled approach to implementing theme-aware UI using CSS variables, prefers-color-scheme, and forced-colors considerations to keep content legible for all users.

Core Features & Use Cases

  • Adhere to WCAG 2.2 contrast requirements in both light and dark modes.
  • Use CSS custom properties to define theme tokens and safely switch themes without hardcoding colors.
  • Provide a keyboard-accessible theme toggle that respects user preferences and persists when possible.
  • Use cases include web apps that support theming, design systems, and components that switch color schemes.

Quick Start

Enable the light/dark theme support in your project, then verify WCAG-compliant contrast in both modes using CSS variables and a theme toggle.

Frequently Asked Questions about light-dark-mode

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement accessible light and dark mode theming using CSS variables?

Accessible light and dark mode theming uses CSS custom properties to define theme tokens, enabling safe color scheme switching without hardcoding values. This approach ensures content remains legible across light, dark, and forced-color modes.

Does prefers-color-scheme support WCAG 2.2 contrast requirements in dark mode?

Yes, prefers-color-scheme can support WCAG 2.2 contrast requirements by pairing it with carefully selected CSS variables. Enforcing accessible color theming ensures both light and dark modes meet the necessary contrast ratios for readability.

What is the best way to build a keyboard-accessible theme toggle for a web app?

The best way to build a keyboard-accessible theme toggle is to use standard controls that respect user preferences and safely store their choice with graceful fallbacks. This ensures the toggle remains usable for all visitors.

How do I handle forced-colors mode when switching between light and dark themes?

Handling forced-colors mode requires applying forced-colors considerations alongside your light and dark theme CSS variables. This principled approach keeps content legible for users who rely on specific high-contrast system settings.

Why does my dark mode implementation fail WCAG contrast checks?

Dark mode implementations often fail WCAG contrast checks when colors are hardcoded instead of using CSS variables to define theme tokens. A principled approach enforcing accessible color theming identifies and corrects these contrast failures.

Can I use this accessible theming approach for a design system?

Yes, you can use this accessible theming approach for design systems and web apps that support theme switching. It applies WCAG-compliant contrast and CSS custom properties to components that switch color schemes.