The read-only property returns an integer that represents the number of style declarations in this CSS declaration block.


var num = styles.length;


An integer that provides the number of styles explictly set on the parent of the instance.


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


Specification Status Comment
CSS Object Model (CSSOM)
The definition of 'CSSStyleDeclaration.length' in that specification.
Working Draft
Document Object Model (DOM) Level 2 Style Specification
The definition of 'CSSStyleDeclaration' in that specification.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
lengthChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support 6WebView Android Full support 4.4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0


Full support  
Full support