This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The CSSStyleDeclaration interface represents an object that is a CSS declaration block, and exposes style information and various style-related methods and properties.
A CSSStyleDeclaration object can be exposed using three different APIs:
HTMLElement.style, which deals with the inline styles of a single element (e.g., <div style="…">).CSSStyleSheet API. For example, document.styleSheets[0].cssRules[0].style returns a CSSStyleDeclaration object on the first CSS rule in the document's first stylesheet.Window.getComputedStyle(), which exposes the CSSStyleDeclaration object as a read-only interface.CSSStyleDeclaration.cssTextTextual representation of the declaration block, if and only if it is exposed via HTMLElement.style. Setting this attribute changes the inline style. If you want a text representation of a computed declaration block, you can get it with JSON.stringify().
CSSStyleDeclaration.length Read only
The number of properties. See the item() method below.
CSSStyleDeclaration.parentRule Read only
The containing CSSRule.
CSSStyleDeclaration.cssFloatSpecial alias for the float CSS property.
CSSStyleDeclaration named propertiesDashed and camel-cased attributes for all supported CSS properties.
CSSStyleDeclaration.getPropertyPriority()Returns the optional priority, "important".
CSSStyleDeclaration.getPropertyValue()Returns the property value given a property name.
CSSStyleDeclaration.item()Returns a CSS property name by its index, or the empty string if the index is out-of-bounds.
CSSStyleDeclaration.removeProperty()Removes a property from the CSS declaration block.
CSSStyleDeclaration.setProperty()Modifies an existing CSS property or creates a new CSS property in the declaration block.
CSSStyleDeclaration.getPropertyCSSValue() Deprecated
Only supported via getComputedStyle in Firefox. Returns the property value as a CSSPrimitiveValue or null for shorthand properties.
const styleObj = document.styleSheets[0].cssRules[0].style;
console.log(styleObj.cssText);
for (let i = styleObj.length; i--; ) {
const nameString = styleObj[i];
styleObj.removeProperty(nameString);
}
console.log(styleObj.cssText);
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
@@iterator |
51 | 18 | 36 | 38 | 11 | 51 | 36 | 41 | 11 | 5.0 | 51 | 11 |
CSSStyleDeclaration |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
cssFloat |
1 | 12 | 1–17 | ≤12.1 | 1 | 18 | 4–17 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
cssText |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
getPropertyCSSValue |
1–40 | No | 1–61Only returns a result if called on the result ofgetComputedStyle(). |
15–27 | 1 | 18–40 | 4–61 | 14–27 | 1 | 1.0–4.0 | 4.4–41 | 1 |
getPropertyPriority |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
getPropertyValue |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
item |
1 | 12 | 1 | ≤12.1 | 6 | 18 | 4 | ≤12.1 | 6 | 1.0 | 4.4 | 6 |
length |
1 | 12 | 1 | ≤12.1 | 6 | 18 | 4 | ≤12.1 | 6 | 1.0 | 4.4 | 6 |
parentRule |
1 | 12 | 1 | 15 | 1 | 18 | 4 | 14 | 1 | 1.0 | 4.4 | 1 |
removeProperty |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
setProperty |
1 | 12 | 1 | 9 | 6 | 18 | 4 | 10.1 | 6 | 1.0 | 4.4 | 6 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration