CSSStyleDeclaration.length

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 Specification
The definition of 'CSSStyleDeclaration' in that specification.
Obsolete

Browser compatibility

DesktopMobile
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

Legend

Full support
Full support