English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSSStyleDeclaration cssText property

 JavaScript CSSStyleDeclaration Object

cssTextSet or return the value of the inline style of the element.

Syntax:

Return cssText property:

element.style.cssText

Set cssText property:

element.style.cssText = style
<h1 id="s1" style="color:red;">CSSStyleDeclaration cssText property</h1>
<p id="result"></p>
<script>
function myFunc() {
   var elem = document.getElementById("s1);
   var output = document.getElementById("result");
   output.innerHTML = elem.style.cssText;   // "color: red;"
}
Test and see‹/›

Browser Compatibility

All browsers fully support the cssText property:

Property
cssTextYesYesYesYesYes

Technical Details

Return Value:A string representing the inline style of the specified element
DOM Version:Secondary Style CSS

More Examples

This example sets the text of the inline style declaration of the element:

document.getElementById("s1").style.cssText = 'color: coral;';
Test and see‹/›

This example sets the color of the element text without using the cssText property:

document.getElementById("s1").style.color = 'coral';
Test and see‹/›

 JavaScript CSSStyleDeclaration Object