CSS: Computed Style
What is Computed Style?
A computed style is all the styles that applies to the element, even if there is no CSS specified for that element.
For example, consider the font size of a element. The element itself may not have a font size value, but it inherit styles from parent element, or from browser's initial value for that property.
Find Computed Style by Browser Console
Use browser's web dev tool to find computed style of a element.
![Chrome browser web dev tool 2019-06-10 txzzv](i/Chrome_browser_web_dev_tool_2019-06-10_txzzv.png)
Get Computed Style by JavaScript
Use
window.getComputedStyle(node).getPropertyValue(propName)
/* xah_get_computed_style (node, propName) return computed property value of string propName of element node version 2019-06-10 */ const xah_get_computed_style = ((node, propName) => window.getComputedStyle(node). getPropertyValue( propName ) ); // -------------------------------------------------- // test const firstPara = document.getElementsByTagName ('p')[0]; const prop = "color"; console.log( xah_get_computed_style(firstPara, prop) );