web api instance property
CSSLayerBlockRule: name property
The read-only name property of the CSSLayerBlockRule interface represents the name of the associated cascade layer.
Value
A string containing the name of the layer, or "" if the layer is anonymous.
Examples
HTML
<output></output> <output></output>
CSS
output {
display: block;
}
@layer special {
div {
color: rebeccapurple;
}
}
@layer {
div {
color: black;
}
}
JavaScript
const item1 = document.getElementsByTagName("output")[0];
const item2 = document.getElementsByTagName("output")[1];
const rules = document.getElementById("css-output").sheet.cssRules;
const layer = rules[1]; // A CSSLayerBlockRule
const anonymous = rules[2]; // An anonymous CSSLayerBlockRule
item1.textContent = `The first CSSLayerBlockRule defines the "${layer.name}" layer.`;
item2.textContent = `A second CSSLayerBlockRule defines a layer with the following name: "${anonymous.name}".`;
Result
Interactive exampleOpen the canonical MDN source to run this embedded demo.
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- The statement declaration of an
@layeris represented by aCSSLayerStatementRule. - How to create named cascade layers in CSS.