interface

Csspagerule — CSS reference

CSSOM interface for a parsed @page rule. selectorText exposes the page selector and style exposes its declarations; nested margin rules are available through cssRules in supporting implementations. Do not use ordinary element selectors to find a page rule.

Formal Syntax & Structure

css syntaxcss
const rule = [...document.styleSheets[0].cssRules].find(r => r instanceof CSSPageRule);

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSSPageRule</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}p{margin:0;font:12px/16px sans-serif}.next{break-before:page}@page{size:300px 400px;margin:40px;}@page wide{size:400px 300px}</style><body><main><p>BODY</p></main><script>const rule = [...document.styleSheets[0].cssRules].find(r => r instanceof CSSPageRule && r.selectorText === "wide"); console.log(rule.selectorText, rule.style.getPropertyValue("size"));</script></body></html>
CSS Reference