This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The StylePropertyMapReadOnly interface of the the CSS Typed Object Model API provides a read-only representation of a CSS declaration block that is an alternative to CSSStyleDeclaration. Retrieve an instance of this interface using Element.computedStyleMap().
Properties
StylePropertyMapReadOnly.size- Returns an unsinged long integer containing the size of the
StylePropertyMapReadOnlyobject.
Methods
StylePropertyMapReadOnly.entries()- Returns an array of a given object's own enumerable property
[key, value]pairs, in the same order as that provided by afor...inloop (the difference being that a for-in loop enumerates properties in the prototype chain as well). StylePropertyMapReadOnly.forEach()- Executes a provided function once for each element of
StylePropertyMapReadOnly. StylePropertyMapReadOnly.get()- Returns the value of the specified property.
StylePropertyMapReadOnly.getAll()- Returns an array of
CSSStyleValueobjects containing the values for the provided property. StylePropertyMapReadOnly.has()- Indicates whether the specified property is in the
StylePropertyMapReadOnlyobject. StylePropertyMapReadOnly.keys()- Returns a new Array Iterator containing the keys for each item in
StylePropertyMapReadOnly. StylePropertyMapReadOnly.values()- Returns a new Array Iterator containing the values for each index in the
StylePropertyMapReadOnlyobject.
Examples
We have to have an element to observe:
<p> This is a paragraph with some text. We can add some CSS, or not. The style map will include all the default and inherted CSS property values. </p> <dl id="output"></dl>
We add a touch of CSS with a custom property to better demonstrate the output:
p {
--someVariable: 1.6em;
--someOtherVariable: translateX(33vw);
--anotherVariable: 42;
line-height: var(--someVariable);
}
We add JavaScript to grab our paragraph and return back a definition list of all the default CSS property values using computedStyleMap().
// get the element
const myElement = document.querySelector('p');
// get the <dl> we'll be populating
const stylesList = document.querySelector('#output');
// Retrieve all computed styles with computedStyleMap()
const stylePropertyMap = myElement.computedStyleMap();
// iterate thru the map of all the properties and values, adding a <dt> and <dd> for each
for (const [prop, val] of stylePropertyMap) {
// properties
const cssProperty = document.createElement('dt');
cssProperty.appendChild(document.createTextNode(prop));
stylesList.appendChild(cssProperty);
// values
const cssValue = document.createElement('dd');
cssValue.appendChild(document.createTextNode(val));
stylesList.appendChild(cssValue);
}
Specifications
| Specification | Status | Comment |
|---|---|---|
| CSS Typed OM Level 1 The definition of 'StylePropertyMapReadOnly' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
StylePropertyMapReadOnly | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
entries | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
forEach | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
get | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
getAll | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
has | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
keys | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
size | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
values | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
@@iterator | Chrome Full support 66 | Edge Full support 79 | Firefox No support No | IE No support No | Opera Full support 53 | Safari No support No | WebView Android Full support 66 | Chrome Android Full support 66 | Firefox Android No support No | Opera Android Full support 47 | Safari iOS No support No | Samsung Internet Android Full support 9.0 |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
