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 »