CLASS Attribute | className Property

DHTML, HTML, & CSS

CLASS Attribute | className Property


Sets or retrieves the class of the object.

Syntax

HTML<ELEMENT CLASS = sClass ... >
Scriptingobject.className [ = sClass ]

Possible Values

sClassString that specifies the class or style rule.

The property is read/write.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see dynamic propertiesInternet Link.

Remarks

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

As of Internet Explorer 5, you can apply multiple styles to an element by specifying more than one style for the CLASS attribute. To apply multiple styles to a single element, use the following syntax:

<ELEMENT CLASS = sClass [ sClass2 [ sClass3 ... ] ] ... >

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 CSS selector used to define the style.

  1. Element
  2. CLASS
  3. ID
  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 cascading style sheetsInternet Link.

Example

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

<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>
This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
A, ACRONYM, ADDRESS, APPLET, AREA, B, BDO, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, custom, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, HEAD, Hn, HR, HTML, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, NEXTID, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, RT, RUBY, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.