Favorites

DOM HTMLElement.style Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
HTMLElement.style
DOM HTMLElement PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

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 = value

Value

A CSSStyleDeclaration object holding the element's inline styles.

Example

<div id="box">Styled box</div>
const box = document.getElementById('box');
box.style.backgroundColor = '#dbeafe';
box.style.padding = '12px';
box.style.setProperty('border-radius', '8px');
console.log(box.getAttribute('style'));
console.log(box.style.color === '');

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.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee