HTML Global class Attribute

❮ Previous Global Attributes Next ❯

Example

<!DOCTYPE html>
</html>
<html>
<head>
<style>
.demo {
	color: red;
}

.bg {
	background: green;
}
</style>
</head>
<body>

<h1 class="demo">Heading</h1>
<p class="demo bg">Paragraph.</p>

</body>
</html>

Meaning

The class attribute specifies the class or classes that a particularly belongs to element belongs.

It can be used by a style sheet to associate style rules with multiple elements or for script access using the getElementsByClassName() method.

Note: Class values are not unique to a particular element

Naming rules:

Description Values
letters A-Z
a-z
digits 0-9
hyphes "-"
underscore "_"



Standard Syntax

<element class="className(s)">



Browser Support




Status







Attribute Values

Value Description
className Specifies one or more class names for an element.
❮ Previous Global Attributes Next ❯