curriculum/challenges/english/blocks/review-css-variables/671a98fbaabfba994e3d9a7c.md
:root {
--bg-color: white;
--text-color: black;
}
.dark-theme {
--bg-color: #333;
--text-color: white;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
}
@property Rule@property rule is a powerful CSS feature that allows developers to define custom properties with greater control over their behavior, including how they animate and their initial values.@property --property-name {
syntax: '<type>';
inherits: true | false;
initial-value: <value>;
}
--property-name: This is the name of the custom property you're defining. Like all custom properties, it must start with two dashes.
syntax: This defines the type of the property, which can be things like <color>, <length>, <number>, <percentage>, or more complex types.inherits: This specifies whether the property should inherit its value from its parent element.initial-value: This sets the default value of the property.@property Rule: This example creates a gradient that smoothly animates when the element is hovered over.:::interactive_editor
<link rel="stylesheet" href="styles.css">
<div class="gradient-box"></div>
@property --gradient-angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
.gradient-box {
width: 100px;
height: 100px;
background: linear-gradient(var(--gradient-angle), red, blue);
transition: --gradient-angle 0.5s;
}
.gradient-box:hover {
--gradient-angle: 90deg;
}
:::
var() function, just as you would with standard custom properties:.button {
background-color: var(--main-color, #3498db);
}
Review the CSS Variables topics and concepts.