Favorites

DOM CSSStyleDeclaration Interface

☕
Enjoying this site?

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

Buy us a coffee
CSSStyleDeclaration
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

CSSStyleDeclaration is an object of CSS properties and values, such as an element's inline style or the result of getComputedStyle().

Description

A CSSStyleDeclaration object represents a block of CSS declarations. You get one from an element's style property (its inline styles, which you can change), from getComputedStyle() (the final, read-only values the browser uses) and from CSS rules in style sheets.

Properties can be read and written in camelCase, style.backgroundColor, or with getPropertyValue() and setProperty() using CSS names, which is also how you work with custom properties such as --main-color.

The style object returned by getComputedStyle() is live: if styles change, reading a property again gives the new value. Properties can also be looped over by index, since the object has a length and numbered entries holding property names, and cssText gets or sets the whole declaration block as one string.

Methods

NameDescription
CSSStyleDeclaration.setProperty()The setProperty() method sets a CSS property on a style object using its CSS name, which is how you set custom properties like --accent from JavaScript.

Example

<div id="box" style="border:2px solid var(--accent, #ccc)">Box</div>
const box = document.getElementById('box');
box.style.padding = '12px';
box.style.setProperty('--accent', 'tomato');
console.log(box.style.cssText);
const computed = getComputedStyle(box);
console.log(computed.display, computed.getPropertyValue('--accent'));

Browser Support

The following information will show you the current browser support for the CSSStyleDeclaration interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface 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