The pattern
:root {
color-scheme: light dark; /* form controls + scrollbars follow */
--bg: #ffffff; --text: #1b1f1d; --card: #f4f5f3; --accent: #0e8a5f;
}
@media (prefers-color-scheme: dark) {
:root { --bg: #111412; --text: #eef1ef; --card: #1b1f1d; --accent: #3fc28b; }
}
body { background: var(--bg); color: var(--text); }
Use the variables everywhere — never hard-code #fff in a component.
A manual toggle
// 'light' | 'dark' | '' (follow the phone)
function setTheme(t) {
document.documentElement.dataset.theme = t;
localStorage.setItem('theme', t);
}
setTheme(localStorage.getItem('theme') || '');
:root[data-theme="dark"] { --bg: #111412; --text: #eef1ef; /* … */ }
:root[data-theme="light"] { color-scheme: light; }
Details that give it away
- Pure black and white — use near-black (#111) and off-white text; it's easier on the eyes.
- Accent colours — lighten them slightly in dark mode so they keep contrast.
- Images with white backgrounds — use transparent PNG/SVG, or soften with
filter: brightness(.9). - Shadows — they disappear on dark backgrounds; use borders instead.
- Launch flash — set the page background colour in the first CSS that loads, not in JavaScript.
Testing
In desktop Chrome DevTools, open Rendering → "Emulate CSS prefers-color-scheme". On the phone, switch dark theme on and reopen the app. If your app ignores the phone setting, the WebView shell may not be passing it through — a manual toggle covers that case.
Building a dark palette that works
| Role | Light | Dark |
|---|---|---|
| Background | #FFFFFF / #F6F7F4 | #111412 |
| Surface (cards) | #FFFFFF | #1B1F1D |
| Text | #1B1F1D | #EEF1EF |
| Muted text | #68706B | #9AA39D |
| Lines | #E3E6E1 | #2A302C |
Dark surfaces get lighter as they come forward — cards are slightly lighter than the background — instead of using shadows. Keep body text contrast at 4.5:1 or more in both themes.
Status bar and splash
The <meta name="theme-color"> tag can take a media attribute, so browsers use the right colour per theme:
<meta name="theme-color" content="#f6f7f4" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#111412" media="(prefers-color-scheme: dark)">
In a built app, the status bar and splash colours come from the app's own settings rather than this tag, so pick a theme colour in the builder that suits both modes — a mid-tone brand colour usually does.
Questions
Does prefers-color-scheme work in Android WebView?
Yes in current WebView versions, for apps that support dark theme. Test on a phone, and add a manual toggle as a fallback.
What does the color-scheme property do?
It tells the engine your page supports light and dark, so built-in form controls, scrollbars and the default background match.
Should dark mode use pure black?
Usually near-black works better; pure black with white text can cause glare and smearing on OLED screens.