docs.rodeo

MDN Web Docs mirror

syntax

{{CSSRef}} 

The syntax descriptor of the {{cssxref("@property")}}  at-rule defines the allowed value types for the registered CSS custom property. It controls how the property’s specified value is processed to derive the {{cssxref("computed_value","computed value")}} . It is a required descriptor; if missing or invalid, the entire @property rule is invalid and ignored.

Syntax

/* A data type name */
syntax: "<color>";

/* A '|' combinator for multiple data types */
syntax: "<length> | <percentage>";

/* Space-separated list of values */
syntax: "<color>+";

/* Comma-separated list of values */
syntax: "<length>#";

/* Keywords */
syntax: "small | medium | large";

/* Combination of data type and keyword */
syntax: "<length> | auto";

/* Universal syntax value */
syntax: "*";

Values

A string (known as the syntax string) that defines the allowed values. It can be one of the following:

The syntax component names can be used alone or multiplied and combined in different ways:

The following syntax component names are supported:

Formal definition

{{cssinfo}} 

Formal syntax

{{csssyntax}} 

Examples

Registering a custom property with type checking

This example shows how to define a custom property --my-color that allows only <color> values:

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

Using JavaScript {{domxref('CSS.registerProperty_static', 'CSS.registerProperty()')}} :

window.CSS.registerProperty({
  name: "--my-color",
  syntax: "<color>",
  inherits: false,
  initialValue: "#c0ffee",
});

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN