<html data-theme='light'>
<head>
<title>CSS Theme</title>
<script>
window.addEventListener("load", () => {
const themePicker = document.getElementById("theme-picker")
themePicker.addEventListener('change', function() {
const theme = this.value
document.querySelector("html").setAttribute("data-theme", theme)
})
})
</script>
</head>
<body>
<div class="card">
<nav>
<select id='theme-picker'>
<option value="light" selected>Light</option>
<option value="dark">Dark</option>
<option value="system">System</option>
<option value="sunset">Sunset</option>
<option value="moonlight">Moon light</option>
<option value="cartoon">Cartoon</option>
<option value="bluecrystal">Blue crystal</option>
</select>
</nav>
<article>
<h2>Heading ...</h2>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown
printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s with the release of
Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem Ipsum
</p>
</article>
</div>
</body>
</html>
@media (prefers-color-scheme: dark) {
html {
--main-bg-color: #000000;
--card-shadow-color: #333333;
--primary-text-color: #ffffff;
--secondry-text-color: #cfcfcf;
}
}
@media (prefers-color-scheme: light) {
html {
--main-bg-color: #a9a9a9;
--card-shadow-color: #878787;
--primary-text-color: #111111;
--secondry-text-color: #333333;
}
}
html[data-theme="light"] {
--main-bg-color: #a9a9a9;
--card-shadow-color: #878787;
--primary-text-color: #111111;
--secondry-text-color: #333333;
}
html[data-theme="dark"] {
--main-bg-color: #000000;
--card-shadow-color: #333333;
--primary-text-color: #ffffff;
--secondry-text-color: #cfcfcf;
}
html[data-theme="sunset"] {
--main-bg-color: #ce8054;
--card-shadow-color: #b35340;
--primary-text-color: #233342;
--secondry-text-color: #4b2b31;
}
html[data-theme="moonlight"] {
--main-bg-color: #232424;
--card-shadow-color: #7f645e;
--primary-text-color: #4c3434;
--secondry-text-color: #4e3c34;
}
html[data-theme="cartoon"] {
--main-bg-color: #303841;
--card-shadow-color: #00adb5;
--primary-text-color: #eeeeee;
--secondry-text-color: #ff5722;
}
html[data-theme="bluecrystal"] {
--main-bg-color: #addfde;
--card-shadow-color: #1f375d;
--primary-text-color: #0c4c8a;
--secondry-text-color: #3f6066;
}
html,
body {
background-color: var(--main-bg-color);
}
.card {
padding: 20px;
box-shadow: 0 4px 8px 0 var(--card-shadow-color);
}
h2 {
color: var(--primary-text-color);
}
p {
color: var(--secondry-text-color);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.