This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The CSSStyleRule interface represents a single CSS style rule.
Inherits properties from its ancestors CSSGroupingRule and CSSRule.
CSSStyleRule.selectorTextReturns 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.
Inherits methods from its ancestors CSSGroupingRule and CSSRule.
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.
| Specification |
|---|
| CSS Object Model (CSSOM)> # the-cssstylerule-interface> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
CSSStyleRule |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
cssRules |
112 | 112 | 117 | 98 | 16.5 | 112 | 117 | 75 | 16.5 | 23.0 | 112 | 16.5 |
deleteRule |
112 | 112 | 117 | 98 | 16.5 | 112 | 117 | 75 | 16.5 | 23.0 | 112 | 16.5 |
insertRule |
112 | 112 | 117 | 98 | 16.5 | 112 | 117 | 75 | 16.5 | 23.0 | 112 | 16.5 |
selectorText |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
style |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
styleMap |
66 | 79 | No | 53 | 16.4 | 66 | No | 47 | 16.4 | 9.0 | 66 | 16.4 |
© 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/CSSStyleRule