Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

W3.JS Add Style to HTML


Add a CSS property value:

w3.addStyle(selector,'property','value')

Add Style by Id

Add a red background color to an element with id="London":

Example

<button onclick="w3.addStyle('#London','background-color','red')">Add Style</button>

Try It Yourself » With CSS »


Add Style by Tag

Add a red background color to all <h2> elements:

Example

<button onclick="w3.addStyle('h2','background-color','red')">Add Style</button>

Try It Yourself » With CSS »


Add Style by Class

Add a red background color to all elements with class="city":

Example

<button onclick="w3.addStyle('.city','background-color','red')">Add Style</button>

Try It Yourself » With CSS »