The CSSStyleDeclaration
API represents an object that is a CSS declaration block, that 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 (<elem style="...">);CSSStyleSheet
API (e.g. document.styleSheets[0].cssRules[0].style
returns a CSSStyleDeclaration
object on the first CSS rule in the document's first stylesheet).CSSStyleDeclaration.cssText
CSSStyleDeclaration.length
Read only
item()
method below.CSSStyleDeclaration.parentRule
Read only
CSSRule
.CSSStyleDeclaration.getPropertyPriority()
CSSStyleDeclaration.getPropertyValue()
CSSStyleDeclaration.item()
CSSStyleDeclaration.removeProperty()
CSSStyleDeclaration.setProperty()
CSSStyleDeclaration.getPropertyCSSValue()
CSSPrimitiveValue
or null
for shorthand properties.var styleObj = document.styleSheets[0].cssRules[0].style; console.log(styleObj.cssText); for (var i = styleObj.length; i--;) { var nameString = styleObj[i]; styleObj.removeProperty(nameString); } console.log(styleObj.cssText);
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) The definition of 'CSSStyleDeclaration' in that specification. | Working Draft | |
Document Object Model (DOM) Level 2 Style Specification The definition of 'CSSStyleDeclaration' in that specification. | Obsolete | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 1 | ? | 1 | ? | Yes | ? |
cssText |
Yes | ? | Yes | ? | Yes | ? |
length |
Yes | Yes | Yes | Yes | Yes | Yes |
item |
Yes | Yes | Yes | Yes | Yes | Yes |
getPropertyValue |
Yes | Yes | Yes | Yes | Yes | Yes |
getPropertyCSSValue
|
? — 41
|
No | ? — 62
|
No | 15 — 28
|
Yes |
getPropertyPriority |
Yes | Yes | Yes | Yes | Yes | Yes |
setProperty |
Yes | Yes | Yes | Yes | Yes | Yes |
removeProperty |
Yes | Yes | Yes | Yes | Yes | Yes |
parentRule |
Yes | Yes | Yes | Yes | Yes | Yes |
cssFloat |
Yes | ? | No | ? | Yes | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | ? | 4 | Yes | ? | ? |
cssText |
Yes | Yes | ? | Yes | Yes | ? | ? |
length |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
item |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
getPropertyValue |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
getPropertyCSSValue
|
Yes | ? — 41
|
No | ? — 62 | 15 — 28
|
Yes | ? |
getPropertyPriority |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
setProperty |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
removeProperty |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
parentRule |
Yes | Yes | Yes | Yes | Yes | Yes | ? |
cssFloat |
Yes | Yes | ? | No | Yes | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration