Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM className property

HTML DOM className property

Element Object Reference Element object


Definition and Usage

The className property sets or returns the class attribute of an element.

Syntax

Get the attribute value:

HTMLElementObject.className

Set the attribute value:

HTMLElementObject.className=

classname


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the className property


Example

Example

Return the class attribute of the body element:

Output result:

Body CSS class: mystyle

An alternate way: mystyle

Try it »


Element Object Reference Element object