CSS var() Function (original) (raw)

Last Updated : 11 Jun, 2026

The CSS var() function is used to access the value of a custom property (CSS variable). It helps make styles reusable, consistent, and easier to maintain across a webpage.

**Syntax:

var(custom_property, value)

**Parameters:

Example: var() function in CSS

html `

var() function
<style>
    :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;
    }
</style>

GeeksforGeeks

var() function

GeeksforGeeks

A computer science portal for geeks

`