Firefox Tomorrow

web api interface

CSSStyleDeclaration

View on MDN ↗

The CSSStyleDeclaration interface is the base class for objects that represent CSS declaration blocks with different supported sets of CSS style information:

The interface exposes style information and various style-related methods and properties. For example, it provides getPropertyValue() for getting the value of a dash-named CSS property, such as border-top, which can’t be directly accessed using dot notation because of the hyphens in its name.

[!NOTE] Earlier versions of the specification used CSSStyleDeclaration to represent all CSS declaration blocks, and some browsers and browser versions may still do so (check the browser compatibility tables for the above APIs). Generally the same website code will be functional in both old and new versions, but some properties returned in a CSSStyleDeclaration may not be relevant in a particular context.

Attributes

  • cssText
    • : Textual representation of the declaration block, if and only if it is exposed via 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().
  • length Read only
    • : The number of properties. See the item() method below.
  • parentRule Read only

CSS Properties

  • CSSStyleDeclaration.cssFloat Deprecated
    • : Special alias for the float CSS property.
  • CSSStyleDeclaration named properties
    • : Dashed and camel-cased attributes for all supported CSS properties.

Instance methods

Example

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);

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.