A CSSRuleList
is an (indirect-modify only) array-like object containing an ordered collection of CSSRule
objects.
Description
Each CSSRule
can be accessed as rules.item(index),
or simply rules[index]
, where rules
is an object implementing the CSSRuleList
interface (such as CSSStylesheet.cssRules
), and index
is the 0-based index of the rule, in the order as it appears in the style sheet CSS. The number of rules in the list is rules.length
.
Note that being indirect-modify (changeable but only having read-methods), rules are NOT added or removed from the list directly, but instead here, only via its parent stylesheet. In fact, .insertRule()
and .deleteRule()
are not even methods of CSSRuleList, but only of CSSStyleSheet
. If however, for some reason the list does need to be modified but has no parent stylesheet (perhaps being a livecopy of a list that does), it cannot just be assigned one (as it has no such property), and neither can it be assigned to one (as stylesheet.cssRules
is read-only), but it must unfortunately be inserted into one, rule by rule, and unless combining lists, after any existing list therein is deleted, rule by rule.
Example
// get the first style sheet’s first rule
var first_rule = document.styleSheets[0].cssRules[0];
See also
CSSRule
CSSRuleList implementations
There are multiple properties in the CSSOM that will return a CSSRuleList
. They are:
CSSStyleSheet
propertycssRules
CSSMediaRule
propertycssRules
CSSKeyframesRule
propertycssRules
CSSMozDocumentRule
propertycssRules
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM)The definition of 'CSSRuleList' in that specification. | Working Draft |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
CSSRuleList
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
? |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
item
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
? |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
length
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 25 |
IE
? |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 25 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
CSSRuleList by Mozilla Contributors is licensed under CC-BY-SA 2.5.