Check computed. Always has a resolved value (or default).
Same property, different sources. Classes/CSS files show up only in computed.
Write with style/classes. Never assign on the computed object.
Example 3 — CamelCase Access
The returned object also exposes camelCase property names.
JavaScript
const styles = getComputedStyle(document.getElementById("box"));
console.log(styles.fontSize); // same idea as getPropertyValue("font-size")
console.log(styles.backgroundColor);
Do math on the number. Add padding, compare sizes, etc.
Layout note. For some properties the resolved value is the used (layout) value.
Compatibility
Browser Support
Window.getComputedStyle() is marked Baseline Widely available on MDN (since July 2015). Browser CSSOM — not a Node.js built-in.
✓ Baseline · Widely available
getComputedStyle()
Read resolved CSS values across modern browsers.
99%Core tag support
ChromeYes
Full support
EdgeYes
Full support
FirefoxYes
Full support
SafariYes
Full support
OperaYes
Full support
HTML element100% supported
Bottom line: Safe default for reading final styles. Prefer classes for writing styles.
Frequently Asked Questions
It returns a live, read-only style object with the resolved CSS values for an element after stylesheets, inheritance, and the cascade are applied.
No. MDN marks Window.getComputedStyle() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
element.style only shows inline styles (the style attribute / JS assignments). getComputedStyle() shows what the browser actually uses, including classes and stylesheets.
No. Computed styles are read-only. Change appearance with element.style, CSS classes, or stylesheets.
An optional string like "::before" or "::after". Pass it as the second argument to read styles of that pseudo-element.
Both work. getPropertyValue("font-size") uses CSS names with hyphens. CamelCase (styles.fontSize) is also supported on the returned object.