HTML class Attribute
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)">
Applies to:
The class attribute can be used on the following element:
| Element | Attribute |
|---|---|
| All HTML elements | class |
Advertisement
Attribute Values
| Value | Description |
|---|---|
| classNames | Specifies the class or classes that a particularly belongs to element belongs. |