{"canonical_url":"https://engineer.company/glossary/css-cascade-layer/","content_markdown":"# CSS cascade layer\n\n## What it is\n\nA CSS cascade layer groups rules and gives those groups an explicit position in\nthe author stylesheet's cascade. The stylesheet can declare an order with\n`@layer reset, vendor, components, theme;` and place rules in those layers\nwherever their source is maintained. For ordinary author declarations of\ncomparable origin and importance, a later layer takes precedence over an earlier\nlayer. Selector specificity still resolves conflicts within the winning layer\nwhen the other relevant cascade criteria match.\n\nDeclaring the order early makes it possible to understand the relationship\nbetween groups before reading all the rules. A later block named `components`\nadds to the existing layer. A stylesheet can also place a dependency in a named\nlayer with the layer form of `@import`, or a build can emit its rules inside the\nintended layer. The delivered CSS determines the actual order.\n\nOrdinary author rules outside named layers take precedence over ordinary layered\nauthor rules. Declarations marked `!important` reverse layer precedence.\nImportant rules inside layers outrank important unlayered rules in the same\norigin, and an earlier layer can beat a later one in that case. This gives\nlayers a clear rule set, but it means the same ordering cannot be used to reason\nabout every declaration.\n\n## Why it matters\n\nStylesheets often grow across separate owners and dependencies. A reset, a\nvendor widget and a local theme may all make reasonable choices in their own\nfiles. Once their rules meet on a page, repeated overrides can turn a simple\nchoice into a contest over selector specificity. With defined layers, a site can\nkeep the lower-priority default and let a shorter, more clearly scoped\ndeclaration win from the group that owns the decision.\n\nThe arrangement also clarifies a migration. A team can decide which rules belong\nto a base layer, which supply component defaults and which are site overrides.\nDeliberate precedence makes it easier to review a dependency update. A more\nspecific rule from a vendor layer can remain subordinate to a normal declaration\nfrom a later component layer.\n\nLayers are part of a larger cascade. Origin and importance still affect the\nresult, and the relevance of a condition still matters. If the issue appears\nonly during printing or with a user preference, first verify which declarations\nactually match in that environment. Layer order can explain the winner only\nafter the browser has a set of relevant declarations.\n\n## What it looks like in practice\n\nConsider a project with a reset, one external component package, local\ncomponents and a site theme. Write the order near the beginning of the assembled\nstylesheet and put the imported component package in the vendor layer. A normal\ntheme rule for a card can override a more specific normal vendor rule for the\nsame property when both match and the competing declarations have the same\norigin. A developer can keep the theme selector small and inspect the winning\nrule in browser tools.\n\nStart with a small part of the stylesheet. Inventory unlayered rules and\nexisting uses of importance before moving any of them. Record the computed\nstyles of the component in its ordinary, focused and disabled states. Check its\nprint presentation and its behaviour with relevant user preferences. Build the\nactual site and repeat the inspection against the final file, especially if the\nCSS bundler changes import handling.\n\nEngineer's\n[reduced motion case study](/portfolio/made-the-reduced-motion-setting-honest/)\ndescribes finding rules that defeated an intended motion override and moving the\nmotion rules into a later shared stylesheet part. The case illustrates how to\nverify an override through the whole site. For a stylesheet using layers,\ndescribe where motion defaults and preference rules belong, then check whether\neach component actually stops the motion it promises to stop.\n\nA short test can exercise a competing normal declaration in two layers and a\nseparate conflict where both declarations are important. Keep those conflicts\nexplicit in the test. Verify the same ordering after changing the import or\nbundling process that produces the deployed asset.\n\n## Where it goes wrong\n\nPartial migrations can make old unlayered rules win over a new layered theme.\nCheck the layer column or matching-rule details in browser tools before adding\nspecificity. Find the declaration that won and decide whether it belongs in the\nlayered order or stays outside it for a known reason. Then verify that the\ndecision also works in every placement of the component.\n\nFirst appearance matters when no earlier statement sets the order. Reordering\nimports or putting a new block above the declaration can create a different\nsequence from the one a reviewer expected. Put the order ahead of the\nparticipating stylesheet rules and inspect the final source. Include declared\norder in the shared entry point even when different files fill the groups.\n\nImportance can create a second kind of surprise. Adding it to a preference\noverride may allow an earlier important declaration to take priority instead.\nInspect the combination of importance, origin and layer before choosing a fix.\nRemove conflicting importance when the component can safely operate under the\nnormal order, or choose the precedence deliberately and check the relevant\nstates.\n\nA useful review leaves each property match understandable. Identify which part\nsupplies the default, which part may override it and whether the final browser\npresentation serves the reader. Carry the same check through focused states,\nmedia preferences and print when those conditions are part of the component.\n\n## Further reading\n\n- [CSS Cascading and Inheritance Level 5 on layers](https://www.w3.org/TR/css-cascade-5/#layering).\n  Defines layer order and its effect on normal and important declarations.\n- [MDN's `@layer` reference](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@layer).\n  Shows syntax for declaring layers and placing rules in them.\n- [CSS Cascading and Inheritance Level 5 on cascade sorting](https://www.w3.org/TR/css-cascade-5/#cascade-sort).\n  Describes how layer precedence interacts with the other cascade criteria.\n\n\u003chttps://engineer.company/glossary/css-cascade-layer/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Order reset, vendor, component and theme rules deliberately and check how layered, unlayered and important declarations interact.","formats":{"gemtext":"https://engineer.company/glossary/css-cascade-layer/index.gmi","gopher":"https://engineer.company/glossary/css-cascade-layer/gophermap","html":"https://engineer.company/glossary/css-cascade-layer/","json":"https://engineer.company/glossary/css-cascade-layer/index.json","markdown":"https://engineer.company/glossary/css-cascade-layer/index.md","pdf":"https://engineer.company/glossary/css-cascade-layer/index.pdf"},"kind":"page","language":"en","title":"What is a CSS cascade layer?","url":"https://engineer.company/glossary/css-cascade-layer/","version":1}