CSSStyleRule.styleMap

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The styleMap read-only property of the CSSStyleRule interface returns a StylePropertyMap object which provides access to the rule's property-value pairs.

Syntax

var stylePropertyMap = cssStyleRule.styleMap;

Value

A StylePropertyMap object.

Example

The following example shows styleMap being used to modify a style using the StylePropertyMap.set() method.

const stylesheet = document.styleSheets[0];

Object.values(stylesheet.cssRules).forEach(block => {
  if (block.selectorText === 'button') {
    block.styleMap.set('--mainColor', 'black');
  }
})

Specifications

Specification
CSS Typed OM Level 2
# dom-cssstylerule-stylemap

Browser compatibility

BCD tables only load in the browser