HTML class Attribute
ExampleUse of the class attribute in an HTML document:
Try it yourself » (more examples at the bottom of this page) |
Definition and Usage
The class attribute specifies a classname 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.
Tips and Notes
Note: The class attribute cannot be used in the following HTML elements: base, head, html, meta, param, script, style, and title.
Tip: It is possible to assign multiple classes to one HTML element, e.g. <span class="left_menu important">. This allows you to combine several CSS classes for one HTML element.
Tip: Do NOT start a class name with a number! This is only supported in Internet Explorer.
Support
W3C: The "W3C" column indicates whether or not the attribute is defined in the W3C HTML/XHTML recommendation.
IE | Firefox | Opera | Safari | W3C |
---|---|---|---|---|
YES | YES | YES | YES | YES |
Syntax
<element class="value"> |
Attribute Values
Value | Description |
---|---|
classname | Specifies the name of a class for an element. To specify multiple classes for one element, separate the classnames with a space |