The CSS @property at-rule
The CSS @property at-rule registers a custom property with a syntax (its type), an initial-value and whether it inherits. The big payoff: a typed custom property can be animated. Registering --angle as an <angle> lets you animate a gradient's rotation — something a plain custom property cannot do.
Overview
A plain custom property is just a string as far as the browser is concerned, which is why you cannot animate one — the browser has no idea how to interpolate between two unknown values. @property fixes that by giving a custom property a real type.
You register it with three descriptors: syntax (the value type, written like "<angle>", "<color>" or "<length>"), an initial-value (a fallback when none is set), and inherits (true or false). Once a property is typed, the browser knows how to animate it — which unlocks effects that were impossible before, like a smoothly rotating conic-gradient driven by an animated --angle.
Beyond animation, registration adds a bit of safety: an invalid value falls back to the initial-value instead of breaking, and the type is enforced. You can also register a property from JavaScript with CSS.registerProperty(), but the @property at-rule keeps it declarative and in your stylesheet where it belongs.
Syntax
@property --angle {
syntax: "<angle>";
initial-value: 0deg;
inherits: false;
}
@keyframes spin { to { --angle: 360deg; } }
.ring {
background: conic-gradient(from var(--angle), #1c7ce9, #6d28d9, #1c7ce9);
animation: spin 3s linear infinite;
}
Example
<style>
@property --a { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
@keyframes spin { to { --a: 360deg; } }
.ring {
width: 96px; height: 96px; border-radius: 50%;
margin: 14px auto;
background: conic-gradient(from var(--a), #1c7ce9, #6d28d9, #1c7ce9);
animation: spin 3s linear infinite;
}
</style>
<div class="ring"></div>
Best practices
- Register a custom property with
@propertywhen you need to animate or transition it. - Always provide an
initial-valueso an invalid or missing value falls back gracefully. - Set
inheritsdeliberately —trueto flow down the tree,falseto stay local. - Write the
syntaxstring with CSS value-type names like<color>,<length>or<angle>.
Frequently asked questions
What is @property in CSS?
How do I animate a CSS variable?
@property and a syntax type (e.g. "<angle>"), then animate it in @keyframes. Plain unregistered variables cannot be animated.What does the syntax descriptor do?
"<color>" or "<length>", so the browser knows how to validate and interpolate it.What is the difference between @property and a plain --variable?
@property gives it a type, an initial value and inheritance, which enables animation and type safety.