Typed custom properties in CSS
@property tells the browser what a variable is, and then it can animate it.
@property --card-angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
@property --card-tint {
syntax: "<color>"; inherits: true; initial-value: #f8fafc;
}
.card {
background: linear-gradient(var(--card-angle), var(--card-tint), white);
transition: --card-angle 400ms ease, --card-tint 400ms ease;
}
.card:hover {
--card-angle: 120deg;
--card-tint: #dbeafe;
}
How it works
syntaxnames the type;<length>and<color>are the common ones.- An untyped variable is a string, and a string cannot be interpolated.
inheritsandinitial-valuecomplete the declaration.
Keywords and builtins used here
backgroundcarddegmspropertytransitionvar
The run, in numbers
- Lines
- 19
- Characters to type
- 375
- Tokens
- 85
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 60 seconds.
Step 3 of 3 in Custom properties, step 7 of 21 in Responsive & modern CSS.