<p>Hello</p>Window: getComputedStyle() method / notebook
Window: getComputedStyle() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
p {
width: 400px;
margin: 0 auto;
padding: 20px;
font: 2rem/2 sans-serif;
text-align: center;
background: purple;
color: white;
}const para = document.querySelector("p");
const compStyles = window.getComputedStyle(para);
para.textContent =
`My computed font-size is ${compStyles.getPropertyValue("font-size")},\n` +
`and my computed line-height is ${compStyles.getPropertyValue(
"line-height",
)}.`;<h3>Generated content</h3>h3::after {
content: " rocks!";
}const h3 = document.querySelector("h3");
const result = getComputedStyle(h3, "::after").content;
console.log("the generated content is: ", result); // returns ' rocks!'