HTML Global class Attribute

❮ Previous Global Attributes Next ❯


<!DOCTYPE html>
.demo {
	color: red;

.bg {
	background: green;

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



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
digits 0-9
hyphes "-"
underscore "_"

Standard Syntax

<element class="className(s)">

Browser Support


Attribute Values

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