On this page
Layers, Scope & Custom Properties
Prev: Media & Container Queries | Up: at_rules | Next: Keyframes, Fonts & Entry Animations
Rel: Cascade, Specificity & Inheritance, Custom Properties & Animation
Ref: MDN Web Docs — @layer
Tags: #public #web #css #at-rules #cascade
Contents
- > `@layer` (Explicit Cascade Ordering)
- > `@scope` (Donut Scoping)
- > `@property` (Typed Animatable Custom Properties)
@layer (Explicit Cascade Ordering)
Declare layer priority upfront so later layers always beat earlier layers regardless of selector specificity (and unlayered styles beat all layered styles for normal declarations):
@layer reset, base, components, utilities;
@layer base {
button.primary { background: gray; }
}
@layer utilities {
.bg-brand { background: oklch(58% 0.18 250); } /* Wins despite lower specificity */
}
@scope (Donut Scoping)
Restricts styles to a subtree and optionally stops at an inner boundary ("donut scope"):
@scope (.card) to (.card-nested) {
p { line-height: 1.5; }
}
@property (Typed Animatable Custom Properties)
Registers a custom property with a CSS syntax type so the browser can interpolate it smoothly in transitions and @keyframes:
@property --angle {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
Linked from
Related notes
- tuts/css/tutorials/cascade_specificity_and_inheritance Linked here; links to this page; shared tags: #cascade, #css, #web
- tuts/css/at_rules Linked here; links to this page; shared tags: #css, #web
- tuts/css/at_rules/keyframes_and_fonts Linked here; links to this page; shared tags: #css, #web
- tuts/css/at_rules/media_and_container_queries Linked here; links to this page; shared tags: #css, #web
- tuts/css/properties/custom_properties_and_animation Linked here; shared tags: #css, #web
- tuts/css shared tags: #css, #web
- tuts/css/functions shared tags: #css, #web
- tuts/css/functions/color shared tags: #css, #web
- tuts/css/functions/color/color-mix shared tags: #css, #web
- tuts/css/functions/color/light-dark shared tags: #css, #web