HTML DOM style Property
Example
Change the color of an element:
document.getElementById("myH1").style.color = "red";
Try it Yourself »
Definition and Usage
The style property returns the value of the element's style attribute.
The style property returns aCSSStyleDeclarationobject.
CSSStyleDeclarationThe object contains all inline attributes of the element, but does not contain<head>some externally set styles.
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 attribute. 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 Yourself »
Other Extensions
Element Object