The WebPlatform project has been discontinued when the Stewards partnership agreement ended in September 2015. This site has been frozen, and the assets we have created will remain.


Jump to: navigation, search


This article is Ready to Use.

W3C Recommendation


Specifies one or more classes for an element, usually used to point to a class in a style sheet.

Applies to dom/HTMLElement


This example uses the class attribute to apply one or more styles to an HTML element.


<!doctype html>
    <style type="text/css">
        p {font-size: 24pt;}
        .redText {color: red;}
        .blueText {color: blue;}
        .italicText {font-style: italic;}
        Large text, no class specified, one implied.
    <p class="redText">
        Large text, .redText class specified.
    <p class="blueText italicText">
        Large text, .blueText and .italicText classes specified.



The property is equal to NULL if the attribute is not explicitly assigned. When multiple styles are specified for an element, a conflict could develop if two or more styles define the same attribute differently. In this case, you can resolve the conflict by applying styles to the element in the following order, according to the Cascading Style Sheets (CSS) selector used to define the style:

  1. Element
  2. Class attribute
  3. ID attribute
  4. Inline styles

When two or more selectors pertain to an element, a style defined later takes precedence over a style defined earlier. For more information, see Introduction to Cascading Style Sheets.


Standards information

Related specifications

Specification Status Related Changes
HTML5 W3C Recommendation


This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]