CSS StyleDeclaration cssText Property
The cssText property is used to set or return the value of an inline style declaration of an element.
Syntax:
- It is used to return the cssText property.
element.style.cssText
- It is also used to set the cssText property.
element.style.cssText = style
Property value:
- style: It is a string literal that specify the style to be added on the element.
Return Value: It returns the inline style of the element in the form of string.
Example-1: To get the cssText property:
<!DOCTYPE html> <html> <head> <title> CSS StyleDeclaration cssText Property </title> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body> <h1> GeeksforGeeks </h1> <!-- Adding inline style --> <p id="p1" style="color:green; font-size:20 "> cssText Property </p> <p> Click the button to get the style </p> <button onclick="myFunction()"> Get style </button> <p id="gfg"> </p> <!-- Script to get cssText property --> <script> function myFunction() { var x = document.getElementById( "p1").style.cssText; document.getElementById( "gfg").innerHTML = x; } </script> </body> </html> |
Output:
- Before clicking on the button:

- After clicking on the button:

Example-2: To set the cssText property:
<!DOCTYPE html> <html> <head> <title> CSS StyleDeclaration cssText Property </title> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <!-- Adding inline style --> <p id="p1" style="color:green; font-size:20 "> cssText Property </p> <p> Click the button to change the style </p> <button onclick="myFunction()"> Set style </button> <p id="gfg"></p> <!-- Script to set cssText property --> <script> function myFunction() { document.getElementById( "p1").style.cssText = "color:blue; font-size:15"; } </script> </body> </html> |
Output:
- Before clicking on the button:

- After clicking on the button:

Supported Browsers: The browsers supported by CSS StyleDeclaration cssText Property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- CSS StyleDeclaration length Property
- CSS | transition-property Property
- CSS | top Property
- CSS | right Property
- CSS | nav-down property
- CSS | nav-right property
- CSS | all Property
- CSS overflow-y Property
- CSS | clip Property
- CSS | perspective Property
- CSS | left Property
- CSS | transition Property
- CSS | align-self Property
- CSS | resize Property
- CSS | flex Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



