Web/API/StyleSheetList

From Get docs


The StyleSheetList interface represents a list of StyleSheet.

It is an array-like object but can't be iterated over using Array methods. However It can be iterated over in a standard for loop over its indices, or converted to an Array.

Examples

Get document styleSheet objects with for loop

for (let i = 0; i < document.styleSheets.length; i++) {
  let styleSheet = document.styleSheets[i];
}

Get all CSS rules for the document using Array methods

const allCSS = [...document.styleSheets]
  .map(styleSheet => {
    try {
      return [...styleSheet.cssRules]
        .map(rule => rule.cssText)
        .join('');
    } catch (e) {
      console.log('Access to stylesheet %s is denied. Ignoring...', styleSheet.href);
    }
  })
  .filter(Boolean)
  .join('\n');

Specifications

Specification Status Comment
CSS Object Model (CSSOM)The definition of 'CSSStyleSheetList' in that specification. Working Draft

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
StyleSheetList Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 31

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 31

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 31

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 31

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 31

IE

?

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 31

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