CSS @property At-Rule

The @property at-rule registers a CSS custom property with a defined value syntax, inheritance behavior, and initial value.

Unlike unregistered custom properties, registered properties are validated against a declared type. They can also interpolate smoothly when their registered value type supports animation.

Syntax

The custom property name must begin with two hyphens. The syntax descriptor is a quoted string, inherits is true or false, and a typed registration requires a valid initial-value.

@property --accent-color {
  syntax: "<color>";
  inherits: false;
  initial-value: #3366cc;
}

Descriptors

A valid registration requires syntax and inherits. The initial-value descriptor is also required unless syntax is "*". Typed initial values must be computationally independent, so a relative value such as 1em cannot be used as the initial value of a registered <length> property.

@property --spacing {
  syntax: "<length>";
  inherits: true;
  initial-value: 12px;
}

Supported Value Types

Common types include <color>, <length>, <percentage>, <number>, <integer>, and <angle>. You can also use supported combinations such as <length-percentage>. The universal syntax "*" accepts any valid token sequence and does not require an initial value.

@property --angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@property --scale {
  syntax: "<number>";
  inherits: false;
  initial-value: 1;
}

Controlling Inheritance

With inherits: false, the child uses the registered initial value navy rather than inheriting crimson from the parent. The child can still explicitly set its own value.

@property --panel-color {
  syntax: "<color>";
  inherits: false;
  initial-value: navy;
}
.parent {
  --panel-color: crimson;
}
.child {
  color: var(--panel-color);
}

Invalid Values and Fallbacks

The registration accepts only a length. The invalid red declaration does not supply a usable value, so the property resolves to its registered initial value of 8px. A fallback argument in var() is not used merely because a registered declaration has an invalid value.

@property --gap {
  syntax: "<length>";
  inherits: false;
  initial-value: 8px;
}
.box {
  --gap: red;
  padding: var(--gap);
}

Animating Registered Properties

Registered percentage values can interpolate smoothly. Hovering transitions --progress, moving the boundary between the two gradient colors. An unregistered custom property generally cannot animate between percentages in the same way.

@property --progress {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}
.bar {
  --progress: 0%;
  background: linear-gradient(90deg, #1476b8 var(--progress), #ddd var(--progress));
  transition: --progress 1s ease;
}
.bar:hover {
  --progress: 100%;
}

@property Example

Hover over the progress bar below to see the registered percentage animate smoothly. The example uses CSS alone, and the editor provides the full working source.

Play in Editor

@property --fill {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 25%;
}
.progress {
  --fill: 25%;
  height: 32px;
  background: linear-gradient(90deg, #126bb0 var(--fill), #e1e5e9 var(--fill));
  transition: --fill 1s ease;
}
.progress:hover {
  --fill: 85%;
}

Browser Support

Baseline Newly available since July 2024. Older browsers may not support registration. Can I Use?

Registered custom properties are not a substitute for validating every author-supplied value. Include a fallback where older browsers might ignore the registration.

Fallback for Older Browsers

Provide a static style for browsers that cannot animate registered custom properties. The fallback can display the same initial state without depending on @property.

.progress {
  background-color: #126bb0;
  background-image: linear-gradient(90deg, #126bb0 25%, #e1e5e9 25%);
}

This fixed gradient provides a usable initial display; the editor demonstrates the animated enhancement in supporting browsers.

Specifications

The @property at-rule is defined in CSS Properties and Values API Level 1, which specifies property registration, supported syntax strings, inheritance, and initial values.

CSS Properties and Values API Level 1