The CSSStyleRule
interface represents a single CSS style rule.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/CSSRule" target="_top"><rect x="1" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="38.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">CSSRule</text></a><polyline points="76,25 86,20 86,30 76,25" stroke="#D4DDE4" fill="none"/><line x1="86" y1="25" x2="116" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleRule" target="_top"><rect x="116" y="1" width="120" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="176" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">CSSStyleRule</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Properties
Inherits properties from its ancestor CSSRule
.
CSSStyleRule.selectorText
- Returns the textual representation of the selector for this rule, e.g.
"h1,h2"
. CSSStyleRule.style
Read only- Returns the
CSSStyleDeclaration
object for the rule. CSSStyleRule.styleMap
Read only- Returns a
StylePropertyMap
object which provides access to the rule's property-value pairs.
Methods
No specific methods; inherits methods from its ancestor CSSRule
.
Examples
The CSS includes one style rule. This will be the first CSSRule
returned by document.styleSheets[0].cssRules
.
myRules[0]
therefore returns a CSSStyleRule
object representing the rule defined for h1
.
h1 {
color: pink;
}
let myRules = document.styleSheets[0].cssRules;
console.log(myRules[0]); // a CSSStyleRule representing the h1.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) The definition of 'CSSStyleRule' in that specification. |
Working Draft | No changes |
Document Object Model (DOM) Level 2 Style Specification The definition of 'CSSRule' in that specification. |
Obsolete |
Browser compatibility
BCD tables only load in the browser