CSSStyleDeclaration cssText attribute

Definition and usage

cssText Set or return the value of the inline (inline) style declaration of the element.

Instance

Example 1

Return the value of the inline style of the h1 element:

var elmnt = document.getElementsByTagName("h1")[0];
var x = elmnt.style.cssText;

Try it yourself

Example 2

Set the inline style declaration text of the element:

document.getElementById("ex1").style.cssText = "color: blue;";

Try it yourself

Syntax

Return the cssText attribute:

element.style.cssText

Set cssText property:

element.style.cssText = style

Technical details

DOM version: Level 2 Style CSS
Return value: A string representing the inline style of the specified element.

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support