5.1 · Logic in CSS

Typed custom properties: @property

Give a custom property a type so the browser can animate it.

A plain custom property is just text to the browser, so it can’t animate it. It only flips from one value to the other halfway through. @property registers a type, an initial value and whether it inherits.

Once --angle is known to be an <angle>, the browser can interpolate it. Gradients, which can’t be transitioned directly, become animatable through their custom properties.

Before
/* Can't animate a gradient.
   Rotate a pseudo-element
   and clip it instead. */
.box::before { animation: rotate 4s; }
Now
@property --angle {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

@keyframes spin { to { --angle: 1turn; } }