This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
CSSPageRule represents a single CSS @page rule.
Inherits properties from its ancestors CSSGroupingRule and CSSRule.
CSSPageRule.selectorTextRepresents the text of the page selector associated with the at-rule.
CSSPageRule.style Read only
Returns the declaration block associated with the at-rule.
Inherits methods from its ancestors CSSGroupingRule and CSSRule.
This example shows how you can find CSSPageRule objects for @page rules loaded by the document.
Below we define styles for the page using a @page rule.
@page {
margin: 1cm;
}
The code iterates through all the sheets in the document, and through all the cssRules in each sheet, logging the sheet index, the number of rules, and the type of each rule object. We then detect CSSPageRule objects using their type (doing nothing with the information).
for (
let sheetCount = 0;
sheetCount < document.styleSheets.length;
sheetCount++
) {
const sheet = document.styleSheets[sheetCount].cssRules;
log(`styleSheet: ${sheetCount}`);
const myRules = document.styleSheets[sheetCount].cssRules;
log(`rules: ${myRules.length}`);
for (const rule of myRules) {
log(`rule: ${rule}`);
if (rule instanceof CSSPageRule) {
// Do something with CSSPageRule
}
}
}
The results are shown below. As you can see there are a two sheets, corresponding to this main document and the example code frame, and each have a number of rules, only one of which is our CSSPageRule.
| Specification |
|---|
| CSS Object Model (CSSOM)> # the-csspagerule-interface> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
CSSPageRule |
1 | 12 | 19 | ≤12.1 | 3 | 18 | 19 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
selectorText |
1 | 12 | 110 | ≤12.1 | 3 | 18 | 110 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
style |
1 | 12 | 19 | ≤12.1 | 3 | 18 | 19 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSPageRule