Skip to content

Instantly share code, notes, and snippets.

:root {
--textcolor: #06c;
}
h1 {
color: var(--textcolor);
}
.wrapper {
--textcolor: #66e387;
}
div {
color: var(--textcolor);
}
<div class="wrapper">
<h1>CSS Variable Are On 🔥</h1>
</div>
<div>
<h1>CSS Variable Are On 🔥</h1>
</div>
:root {
--textcolor: #ffc845;
}
div {
color: var(--textcolor);
}
.wrapper {
--textcolor: #66e387;
}
:root {
--textcolor: #ffc845;
}
.wrapper {
--textcolor: #66e387;
}
document.documentElement.style.setProperty("--textcolor","pink");
document.querySelector('.wrapper').style.setProperty("--textcolor","pink");
.darkmode {
--text: #fff;
--links: #66e387;
--bg-start: #2c5364;
--bg-middle: #203a43;
--bg-end: #0f2027;
--background-fallback: #0f2027; /* fallback for old browsers */
--background-gradient-webkit: -webkit-linear-gradient(
to bottom,
var(--bg-start),
body {
font-size: 1.2rem;
background: var(-background-fallback);
background: var(-background-gradient-webkit);
background: var(-background-gradient);
color: var(-text);
}
a {
color: var(-links-dark);
}