On this page
  1. Layers, Scope & Custom Properties
  2. Contents
  3. @layer (Explicit Cascade Ordering)
  4. @scope (Donut Scoping)
  5. @property (Typed Animatable Custom Properties)

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)

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