W3cubDocs

/DOM

CSSRule.cssText

Not to be confused with element-style CSSStyleDeclaration.cssText.

cssText returns the actual text of a CSSStyleSheet style-rule.

Note: Can no longer be set directly, as now specified to be functionally modify-only -- and *silently* so -- meaning that attempting to set it does absolutely *nothing* -- not even warn or error. Further, it has no settable sub-properties. Therefore, to modify, use the stylesheet's cssRules[index] properties .selectorText and .style (or its sub-properties). See Using dynamic styling information for details.

Syntax

string = cssRule.cssText 

Example

<style>
body { background-color: darkblue; }
</style>
<script>
  var stylesheet = document.styleSheets[0];
  alert(stylesheet.cssRules[0].cssText); // body { background-color: darkblue; }
</script>

Specification

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 1 ? 1 ? Yes ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes 18 ? 4 Yes ? ?

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSRule/cssText