Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk5 min

CSS Cascade Layers: How to Control Style Priority

CSS cascade layers organize style priority. Learn how layer order interacts with specificity, unlayered styles, and !important declarations.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS cascade layers let you set predictable priority groups for stylesheets. For normal declarations, later layers outrank earlier ones, and unlayered author styles outrank all explicitly layered author styles. For !important declarations, that layer order reverses. The cascade checks layer priority before selector specificity, so a lower-specificity rule can win when it is in a higher-priority layer.

Where layers fit in the CSS cascade

Layers are one stage of the cascade, not a replacement for it. A rule must first apply to the element and property in question. The cascade then considers factors including origin and importance, encapsulation context, layer priority, specificity, scoping proximity, and source order. A layer cannot overcome a declaration that already wins at an earlier stage, such as a declaration from a higher-priority origin/importance category. See the W3C CSS Cascading and Inheritance Level 5 specification and MDN’s cascade overview.

For ordinary competing author styles, the useful working sequence is: confirm both rules apply, compare origin and importance, compare context, compare layer, and only then compare specificity and later tie-breakers. A selector that looks stronger may still lose because specificity is not considered until layer precedence is settled. MDN explains the limits of specificity in its specificity guide.

Which CSS layer has priority?

Within the same origin and comparable context, normal declarations in later layers have higher priority than normal declarations in earlier layers. Normal author declarations outside named layers are treated as belonging to an implicit final layer, so they outrank normal declarations in explicit author layers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, the normal-style order below runs from lower to higher priority:

reset < vendor < components < utilities < unlayered author styles

This is why a utility rule can beat a more specific component rule, and why an unlayered rule can unexpectedly beat carefully layered styles. MDN’s cascade layers guide covers the normal and important ordering rules.

Declare layer order before adding styles

A layer’s position is established when its name first appears. Repeating a layer name adds styles to that layer; it does not move the layer to a new position. Declare the intended order near the start of your stylesheet so imports and conditional rules do not establish an unintended order first.

@layer reset, vendor, base, components, utilities;

You can then put declarations in named blocks:

@layer components {
  .card {
    border-radius: 0.5rem;
  }
}

Stylesheets imported with @import can also be assigned to a layer:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
@import url("vendor.css") layer(vendor);

Conditional group rules can affect the global layer order when their conditions create layers. If you need a stable order, declare the names deliberately before conditional blocks. For syntax and additional details, see MDN’s @layer reference.

Use layers to resolve a specificity conflict

In this example, both rules target the same element and property, are normal author declarations, and apply in the same relevant context:

@layer framework, app;

@layer framework {
  #main .button {
    color: navy;
  }
}

@layer app {
  .button {
    color: tomato;
  }
}

The .button declaration in the later app layer wins, even though #main .button is more specific. The cascade settles layer precedence before selector specificity. An unlayered normal author declaration for the same property would outrank both explicit layers.

Layers are useful for separating broad concerns such as resets, vendor styles, application defaults, components, and utilities. The W3C specification describes layers as a way to represent defaults, libraries, themes, components, and overrides, and to reorder their cascade without changing selectors or relying on source order across layers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Important declarations reverse layer priority

For declarations marked !important, layer priority reverses: important declarations in earlier layers outrank important declarations in later layers. Important declarations inside explicit layers also outrank unlayered important author declarations. This exception means you should not assume the normal-style order applies to every declaration. MDN documents this behavior in its !important reference.

Because !important changes the priority model and can make maintenance harder, it is not a dependable everyday override strategy. Prefer an explicit layer order and keep declarations in the intended layers.

Nested layers and conditional rules

Layers can be nested. A name such as framework.theme refers to a theme sublayer nested under framework; its order is considered within that parent. Nested layers are not simply independent top-level layers, and declarations placed directly in a parent have ordering details relative to its nested sublayers. When the exact comparison matters, consult the W3C specification and the @layer reference.

Likewise, layers first encountered inside conditional group rules can make ordering harder to predict. An up-front layer-order statement is a practical safeguard when a stylesheet has media queries, supports conditions, or imports that contribute layers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Diagnose why a rule did not win

  1. Check applicability. Confirm both selectors match the same element and set the same property, and that any media, supports, or other conditions are active.
  2. Compare origin and importance. Determine which origin supplied each declaration and whether either uses !important. These comparisons happen before ordinary layer precedence.
  3. Check context. Confirm the declarations are in comparable encapsulation contexts, such as light DOM versus shadow DOM.
  4. Identify each layer. Find where each layer name first appeared. For normal declarations, the later layer wins; for important declarations, the earlier layer wins. A normal unlayered author declaration beats normal declarations in explicit author layers.
  5. Compare specificity only after those checks. Specificity matters when the earlier cascade comparisons are tied. If specificity is also tied, account for scoping proximity and order of appearance where relevant.

This order of checks avoids the common mistake of increasing selector specificity before finding out that the declaration is losing at the layer stage—or at an earlier stage.

Or skip the browser setup

If you need a rendered screenshot while checking a page, ScreenshotNeo can capture it with one GET request. For example, this cURL command saves a WebP screenshot of the target URL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for request options. It removes cookie or consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents use screenshot tools, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.