layer

@layer

Declares one or more cascade layers so authors can control the order in which rule groups cascade, independent of specificity. Layers declared later win over layers declared earlier, and unlayered styles win over all named layers.

@layer <name> { <rules> }   |   @layer <name>, <name>;

Common conditions / descriptors

Descriptor Purpose
@layer a, b, c; Pre-declare layer order without adding rules yet
@layer name { ... } Add rules into a named layer
@layer { ... } Anonymous layer — order-of-appearance only, no name
@import url(...) layer(name); Import a stylesheet directly into a layer
!important Reverses layer order — earlier layers WIN for !important

Examples

@layer reset, base, components, utilities;

Declare the intended cascade order up front

@layer base {
  h1 { font-size: 2rem; }
}
@layer utilities {
  .text-xl { font-size: 1.25rem !important; }
}

utilities layer wins over base regardless of specificity

@import url('tailwind-base.css') layer(base);

Slot a third-party stylesheet into a specific layer

/* Unlayered rules beat every named layer */
.brand { color: rebeccapurple; }

Keep escape-hatch overrides unlayered

Gotcha

Layer order is set the FIRST time a layer name appears — reopening it later doesn't move it. For !important declarations the layer priority inverts: earlier layers win.

Related at-rules

← All CSS at-rules · CSS properties · CSS selectors