Dark Mode with Web Standards

This article explains how to implement user-controlled dark mode on websites using CSS color-scheme properties and JavaScript. It emphasizes the importance of respecting system preferences while providing users with the flexibility to override settings on a per-site basis.
Why it matters
Improving web accessibility and user experience through standardized dark mode implementation is a best practice for modern web development.
Respecting the user’s OS setting is straightforward: use the prefers-color-scheme media query in CSS. Arguably, that isn’t enough: users should also be able to customise their choice on a per-site basis. A user might want dark mode for the UI of an application, but light mode for reading long-form text on content-heavy sites, for example.
The content is purely instructional and technical, focusing on web standards.
Get smarter about the news
Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.
Create free accountAlready have an account? Sign in