Valid Custom Properties

suggest change

A custom property name is a case-sensitive identifier beginning with two hyphens:

:root {
  --brand-color: rebeccapurple;
  --content-width: 70rem;
  --logo-image: url("/assets/logo.svg");
}

Names such as --brand-color, --Brand-color, and --brand-Color refer to different properties. Choose a consistent naming convention.

The token sequence is substituted where var() is used:

.page {
  color: var(--brand-color);
  max-inline-size: var(--content-width);
  background-image: var(--logo-image);
}

var() cannot concatenate arbitrary token fragments:

/* Invalid after substitution: var() is not string interpolation. */
background-image: url("/assets/" var(--file-name) ".svg");

Store the complete value instead, or construct the URL in HTML or JavaScript.

Custom properties are untyped unless registered. Registering one with @property adds syntax, an initial value, and inheritance behavior:

@property --progress {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

Registration also enables type-aware interpolation when the property is animated.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents