Valid Custom Properties
suggest changeA 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents