Skip to main content
Module 6 · Lesson 4 of 424/60 in the course~18 min
Module lessons (4/4)

Light/Dark Themes Without JS & light-dark()

Lesson preview5 hands-on exercises readyModern HTML & CSS · Color, Contrast, Typography & Design Tokens

Support system preferences and explicit theme switches cleanly via color-scheme and custom property tokens.

What you'll learn in this lesson

  • Respect user OS Light/Dark preferences smoothly using @media (prefers-color-scheme: dark).
  • Inform the browser about supported themes via color-scheme: light dark so native form inputs, scrollbars, and buttons match automatically.
  • Combine OS detection cleanly with an explicit [data-theme="dark"] override hook—or modern light-dark() syntax—using zero-JS CSS tokens.

Overview

Thanks to CSS Custom Properties, building a bulletproof Light/Dark theme requires redefining _only tokens_—every card, button, border, and heading updates everywhere without duplicating structural CSS rules!

Sections covered in this lesson

  1. 1Two Complementary Ways to Build Light & Dark Themes
Pro Lesson · Color, Contrast, Typography & Design Tokens

Unlock "Light/Dark Themes Without JS & light-dark()" and the full Modern HTML & CSS curriculum

Support system preferences and explicit theme switches cleanly via color-scheme and custom property tokens.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Modern HTML & CSS plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.