@property
MDN The @property CSS at-rule is used to explicitly define CSS custom properties, allowing for property type checking and constraining, setting default values, and defining whether a custom property can inherit values or not.
@property --myColor {
syntax: "<color>";
inherits: true;
initial-value: rebeccapurple;
}
@property --myWidth {
syntax: "<length> | <percentage>";
inherits: true;
initial-value: 200px;
}
p {
background-color: var(--myColor);
width: var(--myWidth);
color: white;
} <p>Hello world!</p> Syntax
@property <custom-property-name># { <declaration-list> } Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Browser support
| Chrome | 85 |
|---|---|
| Edge | 85 |
| Firefox | 128 |
| Safari | 16.4 |
| Chrome Android | 85 |
| Safari iOS | 16.4 |
First version with support, from MDN browser-compat-data.
Descriptors
inherits-
true | falseInitial:true initial-value-
<declaration-value>?Initial:the guaranteed-invalid value syntax-
<string>Initial:"*"