🍋
Menu
CSS

Layer

CSS @layer Cascade Layer

A mechanism for organizing CSS into explicit layers that control the order of precedence in the cascade.

Technical Detail

CSS layer is calculated as a tuple (a, b, c): 'a' counts ID selectors, 'b' counts class/attribute/pseudo-class selectors, 'c' counts type/pseudo-element selectors. Inline styles override all selectors. !important overrides inline styles but creates maintenance problems. The new @layer rule (Cascade Layers) adds a fourth dimension to the cascade, allowing authors to define explicit priority ordering for entire groups of styles, reducing specificity wars in large codebases.

Example

```css
/* Specificity: (0,0,1) — type selector */
p { color: black; }

/* Specificity: (0,1,0) — class selector */
.highlight { color: blue; }  /* wins over p */

/* Specificity: (1,0,0) — ID selector */
#title { color: red; }       /* wins over .highlight */
```

Related Formats

Related Tools

Related Terms