Switch your site to dark colours automatically for visitors whose device is set to dark mode.
@media (prefers-color-scheme: dark) {
:root {
color-scheme: dark;
}
body {
background: #15131F;
color: #E4E1EE;
}
a {
color: #A898F0;
}
h1, h2, h3, h4, h5, h6 {
color: #FFFFFF;
}
input, textarea, select {
background: #1F1C2C;
color: #E4E1EE;
border-color: #3A364D;
}
img:not([src$=".svg"]) {
filter: brightness(0.92);
}
}
Many visitors use dark mode on their phones and laptops. A bright white page at night is jarring. This CSS gives your site a dark version that switches on automatically to match their device.
prefers-color-scheme: dark matches when the visitor’s system is set to dark mode. Inside it, the snippet sets a dark background, light text, a lighter link colour and dark form fields. color-scheme: dark tells the browser to draw its own controls, like scrollbars and checkboxes, in dark mode too.
Photos are dimmed slightly so they don’t glare against the dark background. SVG logos are left alone.
Switch your device to dark mode, or in Chrome DevTools open Rendering and set “Emulate CSS media feature prefers-color-scheme” to dark. The site should turn dark.