Skip to content

Instantly share code, notes, and snippets.

Last active February 15, 2020 20:42
What would you like to do?
CSS Dark Mode Media Query with Custom Property usage
<!DOCTYPE html>
<html lang="de">
<title>I'm in the mode</title>
<meta charset="utf-8">
<meta name="description" content="Sometimes I ran…">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="" rel="stylesheet">
:root {
--bg-color: hsla(0, 0%, 90%, 1);
--text-color: hsla(0, 0%, 20%, 1);
*::after {
box-sizing: border-box;
html {
width: 100vw;
height: 100vh;
max-width: 100%;
min-height: 100%;
display: flex;
overflow-x: hidden;
margin: 0;
align-items: center;
justify-content: center;
body {
background-color: var(--bg-color);
color: var(--text-color);
font-family: 'Big Shoulders Text', cursive;
transition: color .2s ease-in, background-color .2s ease-out;
.mode::after {
content: "light";
@media (prefers-color-scheme: dark) {
body {
--bg-color: hsla(0, 0%, 20%, 1);
--text-color: hsla(0,0%, 80%, 1);
.mode::after {
content: "dark";
<section class="hero">
<h1>Welcome to the <span class="mode"></span> mode</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment