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

HTML DOM style property

HTML DOM style property

Element Object Reference Element object

Example

Modify the color of an element:

document

.

getElementById

(

"

myH1

"

)

.

style

.

color

=

"

red

"

;

Try it »


Definition and Usage

The style property returns the value of the element's style attribute.

The style property returns a CSSStyleDeclaration object.

CSSStyleDeclaration The object contains all inline attributes of the element, but does not include the externally set styles applied in some cases.


Browser support

property
style Yes Yes Yes Yes Yes

Syntax

Get the style property:

element.style.property

Set the style property:

element.style.property = value

Technical Details

Return Value:

Returns the value of the specified property.

For example:

element.style.borderBottom = "2px solid red"

More examples

Example

Get the value of the element's style property:

let

value

=

document

.

getElementById

(

"

myP

"

)

.

style

.

borderTop

;

Try it »


Element Object Reference Element object