196 of 264 menu

cssText property

The cssText property allows you to set CSS styles in bulk in one line. In this case, the entire content of the style attribute is overwritten.

Syntax

element.style.cssText = 'property 1: value; property 2: value...'

Example

Let's give an element some styles:

<p id="elem"></p> let elem = document.querySelector('#elem'); elem.style.cssText = 'color: red; font-size: 40px;';

Example

In this example, an element will initially have styles in the style attribute, but the cssText property will overwrite it:

<p id="elem" style="background: red;"></p> let elem = document.querySelector('#elem'); elem.style.cssText = 'color: red; font-size: 20px;';

Example

To prevent previous styles from being overwritten, you can do this:

<p id="elem" style="background: green;"></p> let elem = document.querySelector('#elem'); elem.style.cssText += 'color: red; font-size: 20px;';

See also

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline