W3Schools.com

Style cssText Property

Style Object Reference Style Object

Definition and Usage

The cssText property sets or returns the contents of a style declaration as a string.

Syntax

Set the cssText property:

Object.style.cssText="string"

Return the cssText property:

Object.style.cssText

Value Description
string Specifies the content of a style declaration


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The cssText property is supported in all major browsers.


Example

Example

Get the style declaration as a string:

<html>
<head>
<script type="text/javascript">
function displayResult()
{
alert(document.getElementById("p1").style.cssText);
}
</script>
</head>
<body>

<p id="p1" style="border:2px dashed green;color:red;">This is a paragraph.</p>
<br />
<button type="button" onclick="displayResult()">Get style declaration</button>

</body>
</html>

Try it yourself »


Style Object Reference Style Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE