Enter your email id to get regular update free
Your Email

How to use The class Attribute in HTML?

The class attribute specifies one or more class names for an HTML element.

The class name can be used by CSS and JavaScript to perform certain tasks for elements with the specified class name. 
To select elements in CSS with a specific class write a period (.) character followed by the name of the class.
.name {
 background-color: red;
 color: white;
 padding: 20px;
<h2>class Attribute</h2>
<p>Use CSS to style elements with the class name "name":</p>
<h2 class="name">John</h2>
<p>John is a Doctor.</p>
<h2 class="name">Michel</h2>
<p>Michel is a Lawyer.</p>

class Attribute in JavaScript
JavaScript can access elements with a specified class name by using the getElementsByClassName() method.
function myFunction()
 { var x = document.getElementsByClassName("name");
for (var i = 0; i < x.length; i++)
{ x[i].style.display = "none";
HTML elements can have more than one class name each class name must be separated by a space.
class Attribute
Tech writer at newsandstory
Total 681 views