The initial-value descriptor of the @property at-rule specifies the initial value for the registered CSS custom property. It is a required descriptor unless the syntax descriptor value is the universal syntax (*). If required but missing or invalid, the entire @property rule is invalid and ignored.
initial-value
Baseline 2024
Newly available
Since July 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Syntax
/* Set initial color value */ initial-value: rebeccapurple; /* Set initial length value */ initial-value: 2rem;
Values
Formal definition
| Related at-rule | @property |
|---|---|
| Initial value | n/a (required) |
| Computed value | as specified |
Formal syntax
initial-value =
<declaration-value>?
Examples
Setting an initial value for a custom property
This example shows how to define a custom property --my-color with an initial color value of #c0ffee. This initial value will be used when the property is not inherited (inherits: false) and no other value is set on the element.
@property --my-color {
syntax: "<color>";
inherits: false;
initial-value: #c0ffee;
}
Using JavaScript CSS.registerProperty():
window.CSS.registerProperty({
name: "--my-color",
syntax: "<color>",
inherits: false,
initialValue: "#c0ffee",
});
Specifications
Browser compatibility
| Desktop | Mobile | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | |
initial-value |
85 | 85 | 128 | 71 | 16.4 | 85 | 128 | 60 | 16.4 | 14.0 | 85 |
See also
- Other
@propertydescriptors:inheritsandsyntax - CSS Properties and Values API
- CSS Painting API
- CSS Typed Object Model
- Houdini APIs
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/@property/initial-value