getComputedStyle

getComputedStyle provides access to the final computed style of any element within a document. Click the "View Values" button below to see the computed, and cascaded style values of the div which is styled below. Compare the different values to see when and how the results are different.

External Style Sheet:

#source { 
color:blue !important;
font-family:"courier new";
font-weight: bold;
font-size: 1.5em;
font-style:inherit;
width:75%;
border-color: #ff0000 !important;
border-style: dashed !important;
border-width:.3em;
border-radius:30px;
margin:auto;
padding:2%; }

.sourceclass {
background-color:white !important;
}

Inline Style

style= "color:white;
background-color:red;
border-bottom-style:solid;
border-bottom-color:black;"
                
Property getComputedStyle currentStyle
border-top-width
border-bottom-width
border-right-width
border-left-width
height
margin-top
margin-right
margin-left
margin-bottom
width
border-top-left-radius
border-top-right-radius
border-bottom-right-radius
border-bottom-left-radius
padding-top
padding-right
padding-bottom
padding-left
background-color
border-top-color
border-bottom-color
border-right-color
border-left-color
color
border-top-style
border-bottom-style
border-right-style
border-left-style
font-family
font-size
font-style
font-variant
font-weight

getComputedStyle is a method within the DOM Style specification which provides access to the final computed style of any element within a document. This is helpful because frequently styles may apply to an element from multiple sources. Using the computed style lets you know all of the final styles and final absolute values which applied to the element.

currentStyle is an older API which IE previously supported to retrieve the cascaded style of an element. Cascaded style values are similar to computed values however, they are not always returned in absolute values. For example, in this page, the cascaded value of the width of the source div is 75% but the computed value is given in terms of pixels and will change if you change the width of the page. Another difference to notice between computed and current values is for the height of the source div. The computed height is given in pixel units but the cascaded height simply has a value of "auto" as it is actually not specified in the css anywhere.