The CSS Properties and Values API — part of the CSS Houdini umbrella of APIs — allows developers to explicitly define their CSS custom properties
, allowing for property type checking, default values, and properties that do or do not inherit their value.
On this page
CSS Properties and Values API
Interfaces
-
CSS.registerProperty
-
Defines how a browser should parse a
CSS custom properties
. Access this interface throughCSS.registerProperty
in JavaScript. -
@property
-
Defines how a browser should parse a
CSS custom properties
. Access this interface through@property
at-rule in CSS.
Examples
The following uses CSS.registerProperty
in JavaScript to type a CSS custom properties
, --my-color
, as a color, give it a default value, and not allow it to inherit its value:
js
window.CSS.registerProperty({
name: "--my-color",
syntax: "<color>",
inherits: false,
initialValue: "#c0ffee",
});
The same registration can take place in CSS using the @property
at-rule:
css
@property --my-color {
syntax: "<color>";
inherits: false;
initial-value: #c0ffee;
}
Specifications
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
CSS_Properties_and_Values_API |
78 | 79 | preview | No | 65 | 16.4 | 78 | 78 | No | 56 | 16.4 | 12.0 |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
CSS_Properties_and_Values_API |
85 | 85 | preview | No | 71 | 16.4 | 85 | 85 | No | 60 | 16.4 | 14.0 |
inherits |
85 | 85 | preview | No | 71 | 16.4 | 85 | 85 | No | 60 | 16.4 | 14.0 |
initialValue |
85 | 85 | preview | No | 71 | 16.4 | 85 | 85 | No | 60 | 16.4 | 14.0 |
name |
85 | 85 | preview | No | 71 | 16.4 | 85 | 85 | No | 60 | 16.4 | 14.0 |
syntax |
85 | 85 | preview | No | 71 | 16.4 | 85 | 85 | No | 60 | 16.4 | 14.0 |
api.CSSPropertyRule
BCD tables only load in the browser
api.CSS.registerProperty_static
BCD tables only load in the browser
See also
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSS_Properties_and_Values_API