CSS - @property
Overview
Quick links: Exercises • Checks • Print as PDF
Estimated time: 10–12 minutes
Register custom properties to animate them smoothly and provide type hints.
Learning Objectives
- Register @propertywith syntax and initial values.
- Animate custom properties safely.
Details & Examples
@property --angle { syntax: '<angle>'; initial-value: 0deg; inherits: false; }
.spinner{ --angle: 0deg; transform: rotate(var(--angle)); transition: --angle .6s ease; }
.spinner:hover{ --angle: 90deg; }
Checks for Understanding
- Why define syntaxfor a custom property?
Show answers
- It enables interpolation/animation and authoring-time validation.
Exercises
- Register a --angleproperty and animate a rotation on hover.
- Define a typed color property and transition between two colors.
Suggested answers
- See example above with @property --angleand transition.
- @property --brand { syntax:'<color>'; initial-value:#22c55e; inherits:false }