Easy Tutorial
❮ Tag Span Canvas Globalcompositeoperation ❯

HTML class Attribute

HTML Global Attributes

Example

Using the class attribute in an HTML document:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>tutorialpro.org(tutorialpro.org)</title>
<style>
h1.intro {color:blue;}
p.important {color:green;}
</style>
</head>
<body>

<h1 class="intro">Title 1</h1>
<p>Paragraph.</p>
<p class="important">Note: This is an important paragraph. :)</p>

</body>
</html>

Browser Support

All major browsers support the class attribute.


Definition and Usage

The class attribute specifies the class name for an element.

The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.


Differences Between HTML 4.01 and HTML5

In HTML5, the class attribute can be used on any HTML element (it will validate on any HTML element. However, it is not necessarily useful).

In HTML 4.01, the class attribute cannot be used with: <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.


Syntax

Attribute Values

Value Description
classname Specifies the class name for the element. To specify multiple classes for an element, separate the class names with a space.

<span class="left important">. HTML elements can have multiple classes. Naming rules: Must start with a letter A-Z or a-z<br> Can include the following characters: (A-Za-z), digits (0-9), hyphen ("-"), and underscore ("_")<br> In HTML, class names are case-sensitive |


More Examples

Adding Multiple Classes to an Element


❮ Tag Span Canvas Globalcompositeoperation ❯