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 = divStyles.length; // 3


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 AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 1Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Contributors to this page: connorshea, david_ross, Qantas94Heavy
Last updated by: connorshea,