HTML selectors


There are two type of selectors in HTML.
  • Class
  • Id

Class selector in HTML

Example:

<!DOCTYPE html>
<html>
<head>
<style>
div.id{
background-color:green;
}
</style>
<title>
SELECTORS IN HTML
</title>
</head>
<body>
<div class="id">This is div element.</div>
</body>
</html>

Output:

This is div element.

id selector in HTML

Example:

<!DOCTYPE html>
<html>
<head>
<style>
div#id{
background-color:green;
}
</style>
<title>
SELECTORS IN HTML
</title>
</head>
<body>
<div id="id">This is div element.</div>
</body>
</html>

Output:

This is div element.