Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Custom Properties, Cascade and Global Keywords

The revert-layer keyword

Reference for the CSS revert-layer keyword: how it rolls a property back to the value from the previous cascade layer, with a live @layer example.

The revert-layer keyword is a CSS-wide keyword that cancels the declarations of the current cascade layer for a property. The browser then uses the value the property would have had if that layer had not set it: the value from an earlier layer in the same origin, or, if there is none, from a lower origin.

It is the layer-aware sibling of revert. It is most useful in components that live in a layer and want to switch off one of their own variants without knowing what the base styles are.

CSS
@layer base, components;

@layer components {
  .card.plain {
    background: revert-layer;
  }
}

Try it

Undoing a layer

The .quiet tag sets background: revert-layer inside the theme layer, so the red from theme is dropped and the gold from base shows. Its color has no earlier layer value, so it falls to the browser default.

Syntax

CSS
property: revert-layer;
  • Initial value: not applicable; it is a keyword you write.
  • Applies to: all properties.
  • Inherited: follows the property.
  • Animatable: no.
  • Computed value: the value from the previous layer or origin.

Values

Value Description
revert-layer Ignore declarations of the current layer for this property and use what the cascade would pick from the layers or origins before it.

Usage notes

  • Only meaningful in layers. Outside any @layer, your styles are in the implicit final layer; revert-layer there rolls back to the browser/user origin, much like revert.
  • Layer order matters. "Previous" means earlier in the declared layer order, not earlier in the file.
  • Specificity inside the layer is irrelevant. The whole layer's declaration for that property is dropped, even if another selector in the same layer sets it.
  • Works with all. all: revert-layer drops every property of the layer for that element.
  • Not a toggle. It cannot undo a later layer; layers are rolled back, never forward.

Browser support

Supported in current major browsers alongside cascade layers; check a compatibility table if you must support older versions.