# How to get the value of a CSS property in JavaScript

> Learn how to read the value of any CSS property in JavaScript with getComputedStyle(), including styles set in an external stylesheet, not just inline ones.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2019-07-07 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/javascript-get-css-property-value/

Say you want to fetch the value of a [CSS](https://flaviocopes.com/css) property in a web page, one that is set using a stylesheet.

The `style` property of an element does not return it, because it only lists CSS properties defined in inline styles, or dynamically.

Not the properties defined in an external stylesheet.

So, how do you do it? Use `getComputedStyle()`, a global function:

```js
const element = document.querySelector('.my-element')
const style = getComputedStyle(element)
style.backgroundColor //the RGB value
```
