HTML class Attribute
HTML Standard Attributes
Example
Use of the class attribute in an HTML document:
<html>
<head>
<style type="text/css">
h1.intro {color:blue;}
p.important {color:green;}
</style>
</head>
<body>
<h1 class="intro">Header 1</h1>
<p>A paragraph.</p>
<p class="important">Note that this is an important paragraph.</p>
</body>
</html> |
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
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 |
 |
Try it Yourself - Examples |
Add multiple classes to one element
How to add multiple classes to one HTML element.
HTML Standard Attributes
Create a free Flash website with our simple, online web design editing platform. Stunning templates
and user-friendly tools make website building easy and fun.
Start Creating your free website now!

The Altova MissionKit is an integrated suite of tools ideal for:
- XML development
- Web & Web services development
- Data mapping & integration
- Rendering & publishing XML & database data
- XBRL validation, taxonomy editing, transformation & rendering
The MissionKit for XML Developers includes XMLSpy® - the industry-leading XML editor; MapForce® - a
graphical data mapping, conversion, and integration tool; StyleVision® - a visual XSLT stylesheet designer;
DiffDog® - an XML-aware diff/merge tool; and 2 additional tools.
Try all 6 products free for 30 days!
Download a fully-functional free trial
|
|
|
|