@media (prefers-color-scheme: dark) matches when the OS is in dark mode, letting you ship both themes automatically. Define colors as variables and flip them inside the query. Pair with the color-scheme property so native controls match too.
@media (prefers-color-scheme: dark) matches when the OS is in dark mode, letting you ship both themes automatically. Define colors as variables and flip them inside the query. Pair with the color-scheme property so native controls match too.
<!doctype html><html><head><meta charset="utf-8">
<style>:root{--bg:#f5f0ff;--fg:#1a1133}@media(prefers-color-scheme:dark){:root{--bg:#06040d;--fg:#e6e0ff}}body{background:var(--bg);color:var(--fg);padding:20px}</style></head><body><h1>follows your OS theme</h1></body></html>▶ Open the interactive comic issue