This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.
The read-only layerName property of the CSSImportRule interface returns the name of the cascade layer created by the @import at-rule.
If the created layer is anonymous, the string is empty (""), if no layer has been created, it is the null object.
A string, that can be empty, or the null object.
The document's single stylesheet contains three @import rules. The first declaration imports a stylesheet into a named layer. The second declaration imports a stylesheet into an anonymous layer. The third declaration imports a stylesheet without a layer declaration.
The layerName property returns the name of the layer associated with the imported stylesheet.
@import "style1.css" layer(layer-1); @import "style2.css" layer; @import "style3.css";
const myRules = document.styleSheets[0].cssRules; console.log(myRules[0].layerName); // returns `"layer-1"` console.log(myRules[1].layerName); // returns `""` (an anonymous layer) console.log(myRules[2].layerName); // returns `null`
| Specification |
|---|
| CSS Object Model (CSSOM)> # dom-cssimportrule-layername> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
layerName |
99 | 99 | 97 | 85 | 15.4 | 99 | 97 | 68 | 15.4 | 18.0 | 99 | 15.4 |
@import and @layer
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSImportRule/layerName