CSSRule: cssText property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

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 emit 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.

Value

A string containing the actual text of the CSSStyleSheet rule.

Examples

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

Specifications

Specification
CSS Object Model (CSSOM)
# dom-cssrule-csstext

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
cssText

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support