top of page

HTML class

The HTML class attribute is used to specify a class for an HTML element.

Multiple HTML elements can share the same class.

The class attribute is often used to point to a class name in a style sheet. It can also be used by a JavaScript to access and manipulate elements with the specific class name.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
.place {  % Class can be called by using dot (.) operator%
background-color: green;
  color: wred;
  border: 3px solid blue;
  margin: 25px;
  padding: 15px;
}
</style>
</head>
<body>

<div class="place">
<h2>USA</h2>
<p>United state of America.</p>
</div>

<div class="Place">
<h2>UK</h2>
<p>United Kingdom.</p>
</div>
</body>
</html>

We can also use multiple classes in one html by giving different class names.

HTML id

The HTML id attribute is used to specify a unique id for an HTML element.

The same way as class we can use id for calling in style sheet as well as in java script. The ID in one html will be  unique. ID can be called by using # operator in css or js.

Example: 

<p id="para">This is an example for declaring id</p>

%in style sheet or js we can call this id as #para.

bottom of page