Open In App
Related Articles

CSS var() Function

Improve Article
Save Article
Like Article

The var() function in CSS is used to insert a value for a 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 the custom property must start with two dashes(–).
  • value: It is an optional parameter. It is used if the custom property is invalid.

Example: The 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);
            padding: 10px;
        .gfg2 {
            background-color: var(--main-bg-color);
            padding: 5px;
        h1 {
            color: green;
        body {
            text-align: center;
    <h2>var() function</h2>
    <div class="gfg1">GeeksforGeeks</div><br>
    <div class="gfg2">
          A computer science portal for geeks



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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 15 May, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials