The CSSRule.selectorText property gets the textual representation of the selector for the rule set. This is readonly in some browsers; to set stylesheet rules dynamically cross-browser, see Using dynamic styling information.


string = cssRule.selectorText 


// for cssrule: body { background-color: darkblue; }
var stylesheet = document.styleSheets[0];

alert(stylesheet.cssRules[0].selectorText); // body


The implementation may have stripped out insignificant whitespace while parsing the selector. If set to a selector string which cannot be parsed, a SyntaxError is thrown.

Browser Compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
getting (Yes) ? (Yes) 9.0 (Yes) (Yes)
setting (Yes) ? No support 9.0 (Yes) (Yes)


Document Tags and Contributors

 Contributors to this page: mfluehr, bathos, cuixiping, fscholz, teoli, miket, Sheppy, ethertank, Brettz9, Dria, JesseW
 Last updated by: mfluehr,