DEV Community

Cezary Tomczyk
Cezary Tomczyk

Posted on

Create custom CSS property using @property CSS at-rule

This is interesting. Ever wanted to create a custom CSS property? It seems now that it is possible.

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 and constraining, setting default values, and defining whether a custom 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 registerProperty() had been called with equivalent parameters.

Source: MDN.

Syntax

@property --property-name {
  syntax: "<color>";
  inherits: false;
  initial-value: #c0ffee;
}
Enter fullscreen mode Exit fullscreen mode

Read more about @property on MDN.

Top comments (0)