The read-only property returns an integer that represents the number of style declarations in this CSS declaration block.
Syntax
var num = styles.length;
Value
An integer that provides the number of styles explictly set on the parent of the instance.
Example
The following gets the number of explicitly set styles on the following HTML element:
<div id="div1" style="margin: 0 10px; background-color: #CA1; font-family: monospace"></div>
JavaScript code:
var myDiv = document.getElementById('div1'); var divStyle = myDiv.style; var len = divStyle.length; // 6
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM)The definition of 'CSSStyleDeclaration.length' in that specification. | Working Draft | |
Document Object Model (DOM) Level 2 Style SpecificationThe definition of 'CSSStyleDeclaration' in that specification. | Obsolete |
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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
length
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support Yes |
Opera
Full support Yes |
Safari
Full support 6 |
WebView Android
Full support 4.4 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
CSSStyleDeclaration.length by Mozilla Contributors is licensed under CC-BY-SA 2.5.