Skip to content
Related Articles
Open in App
Not now

Related Articles

CSS | var() Function

Improve Article
Save Article
  • Last Updated : 18 Dec, 2018
Improve Article
Save Article

The var() function in CSS is used to insert a value for custom property.


var( custom_property, value )

Parameters: This function accepts two parameters which are listed below:

  • custom_property: It is the required parameter. The name of custom property must start with two dashes(–).
  • value: It is optional parameter. It is used if custom property is invalid.

Below program illustrates the var() function in CSS:


<!-- HTML code to describes var() function in CSS -->
<!DOCTYPE html>
        <title>var() function</title>
            :root {
                --main-bg-color: Green; 
            /* Use of var() function */
            .gfg1 {
                background-color: var(--main-bg-color);
            .gfg2 {
                background-color: var(--main-bg-color);
                padding: 5px;
            h1 {
            body {
        <h2>var() function</h2>
        <div class = "gfg1">GeeksforGeeks</div><br>
        <div class = "gfg2">A computer science portal for geeks</div>


Supported Browsers: The browser supported by var() function are listed below:

  • Google Chrome 49.0
  • Edge 15.0
  • Firefox 31.0
  • Safari 9.1
  • Opera 36.0

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!