Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

class attribute | className property

The class is typically used to associate a particular style rule in a style sheet with the element.

HTML5 A vocabulary and associated APIs for HTML and XHTML

Syntax

HTML<element class="classNames" ... >
JavaScript

classNames = object.class

Property values

Type: String

One or more CSS classes separated by spaces that are applicable to the element.

Standards information

Remarks

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.

Examples

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


<!doctype html>
<html>
 <head>
    <style TYPE="text/css">
        p {font-size: 24pt;}
        .redText {color: red;}
        .blueText {color: blue;}
        .italicText {font-style: italic;}
    </style>
</head>

<body>
    <p>
        Large text, no class specified, one implied.
    </p>
    <p class="redText">
        Large text, .redText class specified.
    </p>
    <p class="blueText italicText">
        Large text, .blueText and .italicText classes specified.
    </p>
</body>
</html> 


 

 

Show:
© 2014 Microsoft