The cssText property of the CSSRule interface returns the actual text of a CSSStyleSheet style-rule.

Note: Do not confuse this property with element-style CSSStyleDeclaration.cssText.

Be aware that this property can no longer be set directly, as it is now specified to be functionally modify-only, and silently so. In other words, attempting to set it does absolutely nothing, and doesn't even omit a warning or error. Furthermore, it has no settable sub-properties. Therefore, to modify it, use the stylesheet's cssRules[index] properties .selectorText and .style (or its sub-properties). See Using dynamic styling information for details.


string = cssRule.cssText 


  body {
    background-color: darkblue;

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


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

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
cssTextChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support Yes
Full support Yes
Notes The property normalizes rules and does not return the original verbatim rule text. For example, border-width: 1px; border-style:solid; border-color:white; returns border: 1px solid white;.
Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0


Full support  
Full support
See implementation notes.
See implementation notes.