This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

cssText

Summary

Gets or sets a textual representation of a CSS rule.

Property of css/cssom/CSSRule/CSSRulecss/cssom/CSSRule/CSSRule

Syntax

var ruleText = rule.cssText;
rule.cssText = ruleText;

Return Value

Returns an object of type StringString

Returns a textual representation of a CSS rule.

Examples

<div id="myDiv"></div>
<input type="button" value="Blue" id="blueButton">
<input type="button" value="Red" id="redButton">
<script>
    redButton.onclick=function(){
        //create a css style using cssText
        myDiv.style.cssText = "background-image: radial-gradient(red,  yellow); color: darkred;"

        // write the cssText to the contents of the div
        myDiv.innerHTML = "The cssText value is: " + myDiv.style.cssText;
    }
    blueButton.onclick=function(){
        //create a css style using cssText
        myDiv.style.cssText = "background-image: radial-gradient(blue,  white); color: darkblue;"

        // write the cssText to the contents of the div
        myDiv.innerHTML = "The cssText value is: " + myDiv.style.cssText;
    }
</script>

View live example

Related specifications

DOM Level 2 Style
Recommendation

See also

Related articles

CSSOM