@property
Quick Summary for @property
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Code Usage for @property
@property --property-name {   syntax: '<color>';   inherits: false;   initial-value: #c0ffee; } 
More Details for @property

@property

Experimental: This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.

The @property CSS at-rule is part of the CSS Houdini umbrella of APIs, it allows developers to explicitly define their 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 CSS.registerProperty had been called with equivalent parameters.

Syntax

@property --property-name {   syntax: '<color>';   inherits: false;   initial-value: #c0ffee; } 

Descriptors

syntax

Describes the allowable syntax for the property.

inherits

Controls whether the custom property registration specified by @property inherits by default.

initial-value

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 syntax and inherits descriptor; if either are missing, the entire rule is invalid and must be ignored. The 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 custom property, as a color, a default value, and not allow it to inherit its value:

Using CSS @property at-rule:

@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', }); 

Formal syntax

@property <custom-property-name> {   <declaration-list> }

Specifications

Specification
CSS Properties and Values API Level 1 # at-property-rule

See also

CSS Properties and Values API CSS Painting API CSS Typed Object Model CSS Houdini Select your preferred language English (US)Français中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

“Make no mistake: This is not your diary. You are not letting it all hang out. You are picking and choosing every single word.”


Dani Shapiro
Random CSS Property

::spelling-error

Experimental: This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.
::spelling-error css reference