What I mean by the question in the title is: should we always do it? Literally always declare every CSS custom property we make with @property?
Conclusion: Probably not. But perhaps we should declare more often. Let’s take the journey.
Perhaps you scoff at the idea of declaring all custom properties. It is absolutely not required to pre-declare a type for a custom property. You type --whatever: 10px;, and it just works.
But sometimes, it is. The classic example is when you need to animate a value that is set with a custom property. And every time that happens to me, I’m a little confused about why it isn’t working; then I remember, then I have to circle back and declare the thing. Then I forget how to write @property and look it up. Some part of me wishes I had just typed them all to begin with.
So is that the move? Type everything? I dunno, let’s see.
The Syntax
I find this so hard to remember, so I’m sure I’ll reference this exact block of code again in the future:
@property --brand-color {
syntax: "<color>";
inherits: true;
initial-value: rebeccapurple;
}Code language: CSS (css)
Three descriptors:
syntax— the type. Things like<length>,<number>,<percentage>,<color>,<angle>,<length-percentage>, or combos like"<length> | auto". There is also"*", which means “anything,” which is basically an unregistered property.inherits— required.trueorfalse. Leave it out and the whole rule is thrown away.initial-value— required for anything except"*".
There is a JavaScript version too, CSS.registerProperty({ name, syntax, inherits, initialValue }). I’ve never found it useful, but I don’t hate that it exists.
Browser support isn’t much of an issue anymore. Firefox was the last holdout and shipped it in version 128 back in July 2024, which made @property Baseline Newly Available. It should hit Baseline Widely Available in January 2027.
When You Actually Need It
You don’t always need @property to animate something that uses a custom property. This works just fine without registering anything:
.button {
--bg: white;
background-color: var(--bg);
transition: background-color 0.3s;
}
.button:hover {
--bg: #fo6d06;
}Code language: CSS (css)
That transitions smoothly. Why? Because the thing being transitioned is background-color, a real property the browser knows how to interpolate. The custom property just changes the input, the computed background-color changes, and the transition kicks in.
Where it breaks down is when you need the browser to interpolate the custom property itself.
An unregistered custom property is just a bag of tokens to the browser. It has no idea that 0deg and 360deg have a bunch of numbers between them, so it just flips from one to the other. That happens when:
- The custom property is used somewhere that can’t be interpolated on its own, like inside a gradient (gradients are images, and images don’t transition).
- You’re animating the custom property directly in
@keyframesor withtransition: --angle 1s. - One custom property feeds a bunch of
calc()s in different places and you want them all to move together.
Here’s an example where a custom property, --angle, is changed which does a transition or animation. In the top HOVER demo, --angle is changed in the :hover state and we’re just setting the rotate property with it. The @property declaration isn’t needed here. Try visiting the Pen and removing or commenting it out and see it still works.
But if you remove the declaration at the top of the CSS, the DERP example below it stops working. Because there, we’re not just setting a value, the value becomes a part of a complete background declaration for which the --angle is just a part. The @property is required here.
Notice it doesn’t hurt the first demo to declare the property for the second. Declaring it, in this simple demo, is only helpful.
Animation isn’t the only case. In The Compacting Sidebar Blues I needed to register a couple of <length> properties so a style query could compare them with <. Without a type, the browser can’t know 100cqh is a length to resolve and compare. Types are what make the browser actually understand a value instead of just passing it along.
What You Get By Typing Everything
If we just always declared our custom properties, the “why isn’t this animating?!” moment goes away entirely. But there are some other perks as well:
- Bad values fail predictably. If someone sets
--brand-color: 20px, a registered property falls back to itsinitial-value(or the inherited value) instead of passing garbage downstream to wherever it’s used. - It’s documentation. A block of
@propertyrules at the top of a component’s CSS is basically its API. Here’s what you can set, here’s what it expects, here’s the default. Might help both humans and LLMs. - DevTools gets smarter. Chrome DevTools shows the registration info when you inspect a registered property, color swatches show up for
<color>s, and that kind of thing. - Performance, sometimes. The Chrome team benchmarked this. Registering a property with
inherits: truecost basically nothing compared to an unregistered one. Registering withinherits: falsewas dramatically faster to update, because changing it doesn’t invalidate styles for the whole subtree below it. They also found registering a huge pile of properties was a small, one-time cost. Turning off inheritence isn’t something to do blindly though, as we’ll see.
The Downsides (And Foot Guns)
Bigger CSS files
Sure, five-ish lines per property instead of one. It’s more to write and more to read. After compression, it’s not a performance concern; it’s more of a “my tokens file is now three times as long” concern.
I’d say it’s more of a technical debt concern than anything, if you were to do it.
inherits: false is absolutely a foot gun
This is the big one. Unregistered custom properties always inherit, and we’ve all likely built our mental model on that. Design tokens on :root work precisely because of it. Now look:
@property --brand {
syntax: "<color>";
inherits: false;
initial-value: black;
}
:root {
--brand: orangered;
}
button {
/* black! Not orangered. */
background: var(--brand);
}Code language: CSS (css)
The value only applies to the element it’s set on. Every descendant gets the initial-value. If you’re copying-and-pasting @property blocks around (and you will be, because nobody remembers the syntax), it’s very easy to carry an inherits: false into a spot where it silently breaks things.
And the performance tip above tempts you to use inherits: false everywhere! I’d say: default to true, which matches how custom properties have always behaved, and use false on purpose, for things like animation-driving values that are set and consumed on the same element.
Kevin Powell has a good video on a case involving the number of grid columns and intentionally not wanting to have that value inherited.
var() fallbacks stop working
A fallback in var(--x, fallback) only kicks in when the property has no value. A registered property with an initial-value always has a value. So:
@property --card-padding {
syntax: "<length>";
inherits: true;
initial-value: 0px;
}
.card {
/* 0px. The 1rem is never used. */
padding: var(--card-padding, 1rem);
}Code language: CSS (css)
That’s a real problem for the pretty common pattern where a component exposes a custom property “API” and uses fallbacks as its defaults. If you register those, the initial-value becomes the default, and you need to move your defaults up there, which you can only do once, not take advantage of the cascade like you could do otherwise.
You also have to declare initial-value, it’s not optional. Unless you’re declaring syntax: "*";, which honestly I don’t even understand the point of.
Values get computed where they’re declared
An unregistered property inherits its raw tokens and figures out what they mean wherever it’s used. A registered <length> gets computed to an absolute value right where it’s set, and that is what inherits.
@property --space {
syntax: "<length>";
inherits: true;
initial-value: 0px;
}
html {
font-size: 16px;
--space: 2em; /* computes to 32px, right here */
}
h1 {
font-size: 2rem;
/* 32px. Unregistered, it would be 2em of the h1 = 64px. */
margin-block: var(--space);
}Code language: CSS (css)
Neither behavior is wrong, but if you have a spacing system relying on ems resolving locally, typing those properties changes your layout.
The initial-value has rules
It has to be “computationally independent,” which is a fancy way of saying it can’t depend on anything else. No em, no var(), no currentColor-style tricks that need context. initial-value: 1rem is invalid and kills the whole rule. You’ll be writing 16px and feeling a little gross about it.
I think that’s a heck of a footgun that just setting an em or rem value as an initial-value just silently kills the thing.
Types are rigid
Part of the magic of custom properties is that they can hold anything. Half a shorthand. A list of values. Nothing at all, like in the old space-toggle hacks. Something like --shadow-offset: 2px 4px isn’t a <length>, it’s two of them ("<length>+" can handle that, which is a whole new thing). Something that’s sometimes a length and sometimes auto needs "<length> | auto". Typing everything means deciding every value, and some values are deliberately flexible. Like a comma-separated list of values, for example.
Registrations are global
@property doesn’t care about selectors or nesting. If two registrations use the same name, the last one wins, for the whole page. If you’re pulling in third-party CSS, or have components from different teams that all decided to register a --size, you can get some fun mystery bugs. Namespacing your property names helps.
So… Best Practice or Not?
Declaring types for all custom properties, from what we’ve looked at, I’d probably vote no on doing it dogmatically like that. But we should probably declare more than I normally see, with these sort of rules:
- Type properties that hold one clear kind of value: a color, a length, a number, an angle. That’s most of them, and it heads off the “why won’t this animate” moment before it happens.
- Default to
inherits: true, and reach forfalseon purpose (e.g., high churn values). - Move your defaults into
initial-valueand stop relying onvar()fallbacks for registered properties. - Leave the deliberately loose ones alone: multi-value, partial-value, toggle-ish stuff.
- Keep registrations together at the top of a component or tokens file, so they read like an API.
It’s a lot like TypeScript: the extra typing is annoying until it saves you the first time, and then you kinda want it everywhere. Just know the handful of ways it changes behavior, because “add @property to everything” isn’t a no-op refactor.
Sound off, y’all; I’d love to hear opinions on this.