CSS @layer At-Rule

Beginner
6 examples
Updated: Nov 2026

Definition and Usage

@layer groups author styles into an explicit cascade order. A later normal layer can override an earlier one even when the earlier selector is more specific, making frameworks, components, and utilities easier to coordinate.

Declare order early.

@layer reset, base, components, utilities; fixes the order before layer blocks appear.

CSS Syntax

syntax.css
@layer reset, base, components, utilities;
@layer components {
  .button { /* styles */ }
}

Layer Forms

FormPurposeTry it
order statementDeclare named layer priorityTry it
named blockPut rules in a named layerTry it
anonymous blockCreate a layer that cannot be reopened by nameTry it
nested layerCreate sublayers inside a parentTry it
layered importPlace imported styles in a layerTry it
unlayered ruleCompare layered and unlayered priorityTry it

CSS Examples

Set layer order

order.css
@layer reset, base, components, utilities;
Try It Yourself

Component and utility

layers.css
@layer components { .button { color: white; } }
@layer utilities { .text-black { color: black; } }
Try It Yourself

Nested layers

nested.css
@layer framework {
  @layer base, components;
}
Try It Yourself

Browser Support

@layer is a browser cascade feature.

✓ Baseline · Widely available

@layer

Supported by current Chrome, Edge, Firefox, Safari, and Opera.

95% Modern browsers
Google Chrome 99+
Full support
Mozilla Firefox 97+
Full support
Apple Safari 15.4+
Full support
Microsoft Edge 99+
Full support
@layer Widely supported

Bottom line: Safe for current browsers. Keep a sensible source order if older browser behavior matters.

Frequently Asked Questions

It sets cascade priority between groups of author styles before selector specificity is compared.
For normal declarations, a layer listed later has higher priority. Important declarations reverse that layer order.
Normal unlayered author styles have priority over normal declarations inside named layers.
Yes. Nested names such as framework.base create sublayers within a parent layer.
Current Chrome, Edge, Firefox, Safari, and Opera support cascade layers.

Next: @container

Adapt components to their available space.

@container tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful