🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Cascading_variables › Using_custom_properties
Using CSS custom properties (variables) - CSS | MDN
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that represent specific values to be reused throughout a document. They are set using the @property at-rule or by custom property syntax (e.g., --primary-color: blue;). Custom ...
🌐
W3Schools
w3schools.com › css › css3_variables.asp
CSS Variables - The var() function
Static/Relative Position Fixed/Absolute Position Sticky Position Code Challenge CSS Position Offsets ... The var() Function Overriding Variables Variables and JavaScript Variables in MQ Code Challenge CSS @property
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › var
var() - CSS | MDN
The var() CSS function can be used to insert the value of a custom property (sometimes called a "CSS variable") instead of any part of a value of another property.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Properties › --*
Custom properties (--*): CSS variables - CSS | MDN
Property names that are prefixed with --, like --example-name, represent custom properties that contain a value that can be used in other declarations using the var() function.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Environment_variables
CSS environment variables - CSS | MDN
The CSS environment variables module defines the concept of environment variables and the env() function. Environment variables work similarly to custom properties and the var() function, except that they are globally defined; they are global variables scoped to the entire document.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › CSS_cascading_variables
CSS custom properties for cascading variables - CSS | MDN
The CSS custom properties for cascading variables module adds support for cascading variables in CSS properties and lets you create custom properties to define these variables along with the mechanisms to use custom properties as the values for other CSS properties.
🌐
GitHub
github.com › w3c › mdn-spec-links › blob › main › css-variables.json
mdn-spec-links/css-variables.json at main · w3c/mdn-spec-links
"summary": "The var() CSS function can be used to insert the value of a custom property (sometimes called a \"CSS variable\") instead of any part of a value of another property.",
Author   w3c
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Environment_variables › Using
Using environment variables - CSS | MDN
The CSS environment variables module introduces the concept of environment variables in CSS and defines the env() function to enable using environment variables. In this guide, we look at what environment variables are, the environment variables defined by the browser, and how to use environment ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › CSS_properties_and_values_API
CSS properties and values API - CSS | MDN
The CSS properties and values API module defines a method for registering new CSS properties, defining the property's data type, inheritance behavior, and, optionally, an initial value. This API expands on CSS custom properties for cascading variables module, which allows authors to define ...
Find elsewhere
🌐
MDN Web Docs
devdoc.net › web › developer.mozilla.org › en-US › docs › Web › CSS › Using_CSS_variables.html
Using CSS variables - CSS | MDN
CSS Variables are entities defined by CSS authors which contain specific values to be reused throughout a document. 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) ;) .
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › CSSVariableReferenceValue
CSSVariableReferenceValue - Web APIs | MDN
The CSSVariableReferenceValue interface of the CSS Typed Object Model API allows you to create a custom name for a built-in CSS value. This object functionality is sometimes called a "CSS variable" and serves the same purpose as the var() function. The custom name must begin with two dashes.
🌐
web.dev
web.dev › blog › @property: next-gen css variables now with universal browser support
@property: Next-gen CSS variables now with universal browser support | Blog | web.dev
CSS registered custom properties are a very powerful feature that extends the CSS language by providing meaning and context to CSS variables. Now, with @property landing in baseline, this CSS superpower is growing in strength. MDN Web Docs · @property: giving superpowers to CSS variables ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference
CSS reference - CSS | MDN
Use this CSS reference to browse an alphabetical index of all of the standard CSS properties, pseudo-classes, pseudo-elements, data types, functional notations and at-rules. You can also browse key CSS concepts and a list of selectors organized by type. Also included is a brief DOM-CSS / CSSOM ...
🌐
LogRocket
blog.logrocket.com › home › how to use css variables like a pro
How to use CSS variables like a pro - LogRocket Blog
April 3, 2025 - According to the browser compatibility table of the official MDN documentation, the CSS variables feature is widely available in all popular browser versions released after April 2017.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Properties
CSS properties - CSS | MDN
A CSS property is a parameter used in a CSS declaration that lets you style certain aspects of selected elements. For example, the opacity property is used to set the opacity of a selected element, allowing you to control if content behind that element is visible:
🌐
MUI
mui.com › material-ui › customization › css-theme-variables › overview
CSS theme variables - Material UI
CSS theme variables replace raw values in Material UI components for a better developer experience because, in the browser dev tool, you will see which theme token is used as a value.
🌐
Damiancyrus
damiancyrus.com › blog › css-custom-properties
CSS custom properties (CSS variables) | damiancyrus.com
These variables offer significant benefits, such as improving code readability, facilitating maintainable global changes, and providing dynamic control over styles in a live environment.
🌐
Medium
medium.com › swlh › css-variables-618b156777ce
CSS Variables. Move over Sass, we have #CSS variables… | by Samantha Ming | The Startup | Medium
February 19, 2020 - Global scope will allow you to access the variable everywhere. Local scope will just be within your specific selector 👍 · :root { /* 1. Defining in Global Scope */ --color: red; /* 2. Available in all selector*/ color: var(--color); /* red */ }.local { /* 1. Defining in Local Scope */ --color: blue; /* 2. Scoped to the .local class only */ color: var(--color); /* blue */ } It’s been awhile since I had story time, so let’s me share the journey of a discontent css developer who finally stopped being so angry 😂
Top answer
1 of 2
4

When you use the variable without var you set the value to the variable

:root {
  --color: red; /* set a value "red" to the "color" variable */
}

If you want then to get a value from the variable, you need to use var:

.card {
  color: var(--color);  /* get a color from the "--color" variable */
}

From the MDN Docs:

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. 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);).

An example:

:root {
  --color: red; /* set default value for "color" variable */
}


#primary-cards {
  --color: #0F0; /* set custom value for "color" variable in primary cards */
}

.card {
  color: var(--color);  /* use the color variable */
}
<section id="primary-cards">
  <div class='card'>
    My card content
  </div>
</section>

2 of 2
0

<!DOCTYPE html>
<html>
<head>
<style>
  :root{
       /* --color: rbg)1,2,3,4);  error code, or --color variable doesn't exist */
      --blue: blue;
      
      --display-color: red;
      --NoFallBack-to-blue: blue;
      
      }
      
   .red{
      color: var(--display-color, var(--NoFallBack-to-blue))
      }
      
   .blue{
      color: var(--color, var(--blue))
      }
     
</style>
</head>
<body>

<div class="red">
  <p> color will not fallback to blue </p>
</div>


<div class="blue">
  <p> color will fallback to blue </p>
</div>


</body>
</html>

My bad, I didn't read the question, I only read the css code.

You can create a block of css root and assign a value to the declared variable.

For example:

:root {

   --color: rgb(53, 52, 52); 


  /* for fall back */
  --blue: #0000FF;
}

Inside a css selector, let's call the variable

.className{
   
    color: var(--color);
}

lets say --color doesn't exist or forgot to assign a value to the variable.

:root {

       --color: ; 
  
    
      /* for fall back */
      --blue: #0000FF;
    }

It is a fallback when first value doesn't work out then the program will fallback to next value which is --blue. The var(--blue) will display on the screen

.className{

    color: --var(--color, var(--blue))
}