Questions tagged [css-variables]

Custom properties (or CSS variables) allow to define stylesheet-wide values identified by a token and usable in all CSS declarations.

Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific values to be reused throughout a document.

developer.mozilla

They are set using custom property notation (e.g., --main-color: black;) and are accessed using the var() function (e.g., color: var(--main-color);).

Example

/* Declaring a variable */
:root {
  --main-bg-color: brown;
}

/* Using the variable */
element {
  background-color: var(--main-bg-color);
}
625 questions
-1
votes
1 answer

Is it possible to change a css variable using js setProperty with a value of another js variable?

I have an input field, in which, user is supposed to enter the color of text, that he want's to be displayed later. I was wondering, if there is a way to change css variables with javascript setProperty function, and instead of a value, the argument…
-1
votes
2 answers

Will my js script break by setting css --variables on legacy browsers?

I want to start using css --variables. For legacy browsers, the css fallback is to declare a legacy rule first, and that's fine. But then I will manipulate them via javascript. So, is it going to break the script and throw some errors in legacy…
Luca Reghellin
  • 7,426
  • 12
  • 73
  • 118
-1
votes
1 answer

How to create an HTML document that allow switch themes using pure HTML and CSS?

How to create a document that allow switch themes using HTML and CSS ? (without JavaScript) I created simple HTML document : Document