Registered Custom Properties With @property: Types, Inheritance and Animation
Giving custom properties a type with @property and CSS.registerProperty(): syntax strings, inherits and initial-value, type checking, values computed like real properties, animating gradients and numbers, and the rules registration follows.
kvi5hnuCode Sprout team member7 min readOn this page
An ordinary custom property (article 27) is untyped: the browser stores whatever text you give it and only finds out whether it makes sense when it's used. Registering the property gives it a type, an initial value and an inheritance setting. That changes what the browser can do with it: check values, compute them like real properties, and, most visibly, animate them.
The @property rule
@property --angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
| Descriptor | Meaning | Required |
|---|---|---|
syntax | the type of value allowed, as a string | yes |
inherits | whether the value inherits to descendants, true or false | yes |
initial-value | the value when nothing sets it | yes, unless syntax is "*" |
If a required descriptor is missing or invalid, the whole rule is ignored, and the property stays an unregistered, untyped one. That failure is silent, so check registration in DevTools, which shows registered properties and their values.
Syntax strings
The syntax descriptor names a data type, in quotes:
| Syntax | Accepts |
|---|---|
"<length>", "<percentage>", "<length-percentage>" | lengths, percentages, or either |
"<number>", "<integer>" | numbers |
"<angle>", "<time>", "<resolution>" | angles (45deg), times (200ms), resolutions (2x) |
"<color>" | any color |
"<image>", "<url>" | images and gradients, or url() values |
"<transform-function>", "<transform-list>" | one transform function, or a list such as rotate(5deg) scale(1.1) |
"<custom-ident>" | any identifier |
"*" | anything: the same as an unregistered property |
Syntax strings can be combined:
|means "or":"<length> | auto", or keywords alone,"small | medium | large".+means a space-separated list:"<length>+"accepts1px 2px 4px.#means a comma-separated list:"<color>#".
What registration changes
Type checking
A value that doesn't match the syntax is invalid at computed-value time. The property then gets its initial value, or inherits if inherits is true:
@property --hue { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
.chip { --hue: 20deg; }
.chip { --hue: 15%; } /* not an angle: --hue becomes 0deg, not 20deg */
Because a registered property always has a valid value, the fallback in var(--hue, 200deg) is never used, except for syntax: "*" properties without an initial value.
Values are computed
An unregistered property passes its raw text down, so --size: 2em means a different length in every element that uses it. A registered <length> is computed where it's declared, like font-size or width, and the computed length inherits:
@property --pad { syntax: "<length>"; inherits: true; initial-value: 0px; }
.card { font-size: 20px; --pad: 2em; } /* computed: 40px */
.card small { font-size: 10px; padding: var(--pad); } /* 40px, not 20px */

Same declarations, double the padding: registration decides where 2em turns into pixels.
Choose whichever behavior you need: register for a fixed length, or leave the property unregistered to re-resolve em in each element.
Non-inheriting properties
With inherits: false, every element starts from the initial value unless a rule sets the property on it. That's useful for per-element settings that shouldn't leak into nested components, such as a --progress on one bar, a --rotation on one icon. It's also slightly faster: the browser doesn't recompute descendants when the value changes.
Animation and transitions
The browser can interpolate a registered property, because it knows the type. This is the feature that makes @property worth knowing: it lets you animate things that have no property of their own, such as a gradient's angle or color stops, or a number shown with a counter.
@property --angle { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
@property --stop { syntax: "<percentage>"; inherits: false; initial-value: 10%; }
@property --count { syntax: "<integer>"; inherits: false; initial-value: 0; }
body { font-family: system-ui, sans-serif; display: flex; gap: 1.5rem; align-items: center; padding: 1rem; }
.ring {
width: 7rem; height: 7rem; border-radius: 50%;
background: conic-gradient(from var(--angle), #8a3b12, #f4c95d, #2f7d4f, #8a3b12);
animation: spin 4s linear infinite;
}
@keyframes spin { to { --angle: 360deg; } }
.fill {
width: 9rem; height: 7rem; border-radius: 10px;
background: linear-gradient(to top, #2f7d4f var(--stop), #e8e1d4 var(--stop));
animation: fill 3s ease-in-out infinite alternate;
}
@keyframes fill { to { --stop: 90%; } }
.counter { font: 700 2.5rem system-ui, sans-serif; color: #8a3b12;
counter-reset: n var(--count); animation: count 3s steps(60) infinite alternate; }
.counter::after { content: counter(n) "%"; }
@keyframes count { to { --count: 100; } }
Without the @property rules, each animation would jump between its start and end values, because untyped properties only animate discretely.

The unregistered rows show the discrete behavior: the value flips from the start to the end value halfway through, with nothing in between. Transitions work the same way:
@property --button-hue { syntax: "<angle>"; inherits: false; initial-value: 25deg; }
.button { background: oklch(0.5 0.13 var(--button-hue)); transition: --button-hue 300ms; }
.button:hover { --button-hue: 145deg; }
Registering from JavaScript
CSS.registerProperty() does the same as @property:
CSS.registerProperty({
name: "--progress",
syntax: "<percentage>",
inherits: false,
initialValue: "0%",
});
- Registering the same name twice in JavaScript throws an
InvalidModificationError. A JavaScript registration also takes precedence over@propertyrules for that name. - With
@property, if several rules register the same name, the last one wins.
Rules for initial values
The initial value must be computationally independent: it can't depend on anything about an element. So initial-value: 2em or initial-value: var(--x) makes the rule invalid, because there's no font size to resolve em against. Absolute lengths such as 0px, colors, numbers and angles are fine.
Limitations
- Shadow DOM: browsers currently ignore
@propertyrules in shadow roots. Web components need to register their properties in the document, or withCSS.registerProperty(). - Discrete types:
<custom-ident>, keyword lists and<url>can't interpolate, so they still flip during animations. - Lists:
"<length>+"interpolates only between lists of the same length. - Global names: registration applies to the whole document, so name properties to avoid collisions between components.
What's current
@propertyandCSS.registerProperty()are Baseline since July 2024, when Firefox 128 added them. Chrome has had them since 2020, and Safari since 16.4 (2023).- Typed
attr()(article 30) uses the same syntax strings to parse attribute values.
Common questions
Why doesn't my custom property transition?
Unregistered custom properties have no type, so a transition can't interpolate them: the value switches immediately, or at the halfway point with transition-behavior: allow-discrete. Register it with @property and a syntax such as "<color>" or "<length>".
Why is my @property rule ignored?
Usually a missing inherits descriptor, a missing initial-value, or an initial value that isn't computationally independent, such as 2em. The syntax must also be a quoted string.
Should I register every custom property? No. Register those you animate, those that need type checking or a guaranteed value, and those that shouldn't inherit. Unregistered properties are simpler and can hold any text.
Why does my registered --size: 2em give the same pixel size in every nested element?
A registered length is computed to an absolute length where it's declared, and that value inherits. An unregistered property would pass the text 2em along, and each element would resolve it with its own font size.
Summary
@propertygives a custom property asyntax, aninheritssetting and aninitial-value. Missing or invalid descriptors make the whole rule ignored.- Syntax strings name types like
"<length>"or"<color>", and combine with|,+and#. - Values that don't match become invalid at computed-value time and fall back to the initial value or the inherited one.
- Registered values are computed where they're declared, like real properties.
inherits: falsekeeps values on the element that sets them.- Registered properties can be transitioned and animated, which allows animated gradients and counters.
- Initial values must be computationally independent.
@propertyis ignored in shadow roots.
Practice questions
Register a --progress property that a progress bar can transition from 0% to any percentage, without the value leaking into nested elements.
Answer
@property --progress {
syntax: "<percentage>";
inherits: false;
initial-value: 0%;
}
.bar { background: linear-gradient(to right, #2f7d4f var(--progress), #ddd 0);
transition: --progress 400ms ease-out; }
What's wrong with this rule?
@property --gap { syntax: "<length>"; initial-value: 1em; }
Answer
Two things: inherits is missing, and 1em isn't computationally independent. Either makes the rule invalid, so --gap stays unregistered. Add inherits: true; (or false) and use an absolute value such as 16px.
With the registration below, what's the value of --size in an element that has --size: 10px; and then --size: blue; in a later rule?
@property --size {
syntax: "<length>";
inherits: false;
initial-value: 4px;
}
Answer
4px. The later declaration wins the cascade, but blue doesn't match <length>, so it's invalid at computed-value time. The property doesn't inherit, so it takes the initial value. The earlier 10px isn't used.
How would you make a number count from 0 to 250 with CSS alone?
Answer
Register an <integer> property, animate it, and display it with a counter:
@property --n { syntax: "<integer>"; inherits: false; initial-value: 0; }
.total { counter-reset: n var(--n); animation: up 2s forwards; }
.total::after { content: counter(n); }
@keyframes up { to { --n: 250; } }
Previous: Custom Properties: Variables, Fallbacks, Scope and Changing Them at Runtime
Next: Angles, Times, Resolutions, Ratios, Positions and Images

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.