Web/API/CSSStyleDeclaration/length

From Get docs

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

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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