Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

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 »