DOM HTMLElement.style Property
The style property gives access to an element's inline styles, so you can read or change individual CSS properties from JavaScript.
Description
The style property returns a CSSStyleDeclaration for the element's inline styles, the ones in its style attribute. Set properties in camelCase, el.style.backgroundColor = 'red', or with setProperty() using CSS names and custom properties. Setting a property to an empty string removes it.
Reading style only shows inline styles, not those from style sheets; use getComputedStyle() for the final values. For anything beyond one-off changes, toggling a class with classList keeps styling in your CSS where it belongs.
Values must be strings with units where CSS needs them, so el.style.width = 100 is ignored, while '100px' works. Setting el.style.cssText replaces all inline styles at once, and el.style.removeProperty('color') removes one.
Syntax
element.style
element.style.property = valueValue
A CSSStyleDeclaration object holding the element's inline styles.
Example
Browser Support
The following information will show you the current browser support for the HTMLElement.style property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





