Widely available Supported across all major browsers. Safe to use in production.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
49
15
31
9.1
49
9.3
Other

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.

49
15
31
9.1
49
9.3
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

CSS
:root {
  --color-primary: #2563eb;
  --color-bg: #ffffff;
  --spacing-md: 1rem;
}

.card {
  background: var(--color-bg);
  padding: var(--spacing-md);
  border: 1px solid var(--color-primary);
}

/* Dark theme */
[data-theme="dark"] {
  --color-primary: #60a5fa;
  --color-bg: #1e293b;
}

/* Fallback values */
.text {
  color: var(--color-text, #333);
}

Live demo

Cssvariable in themedefinition

CSS Custom Properties (CSS Variables) CSSvariable in themedefinition demo.

PreviewFullscreen

variable. Toggle

CSS Custom Properties (CSS Variables) variable. Toggle demo.

PreviewFullscreen

fo-backvalue

CSS Custom Properties (CSS Variables) fo-backvalue demo.

PreviewFullscreen

Use cases

  • Using Custom properties

    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.

Cautions

  • May not be supported in older browsers.

Accessibility

  • Make sure visual changes are conveyed appropriately to assistive technology.