CSSRule.cssText

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.

Syntax

string = cssRule.cssText

Example

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
cssText
1
12
1
9
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;.
≤12.1
1
1
18
4
≤12.1
1
1.0

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSRule/cssText