class of an element


class=""

Browser
Internet Explorer Firefox Opera

The class attribute assigns one or more class names to an element. (It is used to apply styles to elements.)

This attribute can be used in most elements.


<p class="example"> - </p>


Attribute Value Explanation
class=" " class name arbitrary name

Two or more elements can have the same class name.


Example

<html>
<head>
<title>TAG index</title>

<style type="text/css">
.example1 { color: red; font-size: 100%; }
.example2 { color: green; }
</style>

</head>
<body>

<h1 class="example1">The class name is example1</h1>
<p class="example2">The class name is example2</p>
<p class="example2">The class name is example2</p>

</body>
</html>
Output

The class name is example1

The class name is example2

The class name is example2