Favorites

DOM Window.getComputedStyle() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.getComputedStyle()
DOM Window MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The getComputedStyle() method returns the final values of all CSS properties of an element, after style sheets, inheritance and inline styles are applied.

Description

The getComputedStyle() method returns an object with the resolved values of every CSS property of an element, after all style sheets, inherited values and inline styles are applied. Values are generally in absolute units, such as pixels and rgb() colours. It can also read pseudo-elements such as ::before, and custom properties with getPropertyValue('--name').

The result is read-only; to change styles, use the element's style property or classes. Reading computed styles can force a layout calculation, so avoid doing it in tight loops.

Shorthand properties such as margin may return an empty string in some browsers; read the individual longhands, such as marginTop, instead. For hidden elements with display: none, layout-dependent values such as width may be reported as auto, since the element has no layout.

Syntax

getComputedStyle(element)
getComputedStyle(element, pseudoElement)

Parameters

  • elementThe element to get styles for.
  • pseudoElementOptional. A pseudo-element such as "::before".

Return Value

A live, read-only CSSStyleDeclaration of the element's final style values.

Example

<style>#el{font-size:1.25rem;color:teal;--gap:12px}#el::before{content:"★ "}</style>
<p id="el">Styled text</p>
const el = document.getElementById('el');
const cs = getComputedStyle(el);
console.log(cs.fontSize, cs.color, cs.display);
console.log(cs.getPropertyValue('--gap').trim());
console.log(getComputedStyle(el, '::before').content);

Browser Support

The following information will show you the current browser support for the Window.getComputedStyle() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee