The @property Rule for Typed Custom Properties
- CSS Basics
- Selectors & Specificity
- Box Model & Units
- Typography & Text Styling
- Colors & Color Spaces
- Positioning & Stacking Context
- Flexbox
- Grid
- Grid Advanced
- Responsive Design
- Container Queries
- Pseudo-classes & Pseudo-elements
- Modern Selectors
- CSS Custom Properties
- CSS Functions
- Transitions & Animations
- Transforms
- Forms & Input Styling
- CSS Architecture & Methodologies
- Accessibility in CSS
- Performance & Optimization
- View Transitions & Modern APIs
- Cascade Layers & Scope
A Limitation of Ordinary Custom Properties
A regular custom property, as covered elsewhere in this section, is essentially just stored text - the browser does not know whether --my-color is meant to be a color, a number, or a length, which prevents it from being safely animated or transitioned in some cases.
What @property Adds
@property --highlight-color {
syntax: '<color>';
inherits: false;
initial-value: #1d4ed8;
}@property registers a custom property with an explicit type (syntax), whether it should inherit down to child elements, and a required fallback (initial-value) - turning a plain text variable into something the browser actually understands and validates.
Why This Enables Smooth Animation
.gradient-box {
background: linear-gradient(to right, var(--highlight-color), white);
transition: --highlight-color 0.3s ease;
}
.gradient-box:hover {
--highlight-color: #dc2626;
}Without registering --highlight-color as a <color> type, the browser cannot interpolate smoothly between two color values - it can only jump instantly between them. Once typed with @property, the color can transition through intermediate shades exactly like any other native color property.
Common syntax Type Values
| Syntax value | Accepts |
|---|---|
'<color>' | Any valid CSS color |
'<length>' | A size like 10px or 2rem |
'<percentage>' | A percentage value |
'<number>' | A plain unitless number |
Why This Matters for Design Systems
Typed custom properties bring CSS variables closer to how variables behave in a real programming language - validated, predictable, and safely animatable - which is especially valuable in larger design systems where many components share the same set of variables.