All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

Implementing dark mode with CSS and minimal JavaScript using prefers-color-scheme

By

thm

6h ago· 6 min readen

Summary

This article explains how to implement dark mode on websites using web standards, specifically the prefers-color-scheme media query in CSS. It covers supporting the user's OS-level system setting as a default, while also providing a per-site toggle for users to override that setting. The approach emphasizes minimal JavaScript usage and standard CSS techniques.

Source

Hacker NewsImplementing dark mode with CSS and minimal JavaScript using prefers-color-schemeolliewilliams.xyz

Key quotes

· 3 pulled
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.
Snippet from the RSS feed
Implementing dark mode with minimal JavaScript and standard CSS

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.