Path: blob/main/files/en-us/web/css/@property/index.md
6509 views
------{{CSSRef}}{{SeeCompatTable}}
The @property CSS at-rule is part of the CSS Houdini umbrella of APIs, it allows developers to explicitly define their {{cssxref('--*', 'CSS custom properties')}}, allowing for property type checking, setting default values, and define whether a property can inherit values or not.
The @property rule represents a custom property registration directly in a stylesheet without having to run any JS. Valid @property rules result in a registered custom property, as if {{domxref('CSS.registerProperty')}} had been called with equivalent parameters.
Syntax
Descriptors
{{cssxref("@property/syntax","syntax")}} {{Experimental_Inline}}
: Describes the allowable syntax for the property.
{{cssxref("@property/inherits","inherits")}} {{Experimental_Inline}}
: Controls whether the custom property registration specified by
@propertyinherits by default.
{{cssxref("@property/initial-value","initial-value")}} {{Experimental_Inline}}
: Sets the initial value for the property.
A valid @property rule represents a custom property registration, with the property name being the serialization of the in the rule's prelude.
@property rules require a {{cssxref("@property/syntax","syntax")}} and {{cssxref("@property/inherits","inherits")}} descriptor; if either are missing, the entire rule is invalid and must be ignored. The {{cssxref("@property/initial-value","initial-value")}} descriptor is optional only if the syntax is the universal syntax definition, otherwise the descriptor is required; if it's missing, the entire rule is invalid and must be ignored.
Unknown descriptors are invalid and ignored, but do not invalidate the @property rule.
Examples
Add type checking to --my-color {{cssxref('--*', 'custom property')}}, as a color, a default value, and not allow it to inherit its value:
Using CSS {{cssxref('@property')}} at-rule:
Using JavaScript {{domxref('CSS.registerProperty')}}:
Formal syntax
{{csssyntax}}
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}