CSS @page At-Rule

Beginner
3 examples
Updated: Nov 2026

Definition and Usage

The @page at-rule styles printed pages. Set size and margins for the page box so print and print-preview output look intentional.

CSS Syntax

syntax.css
@page {
  size: A4;
  margin: 2cm;
}

Key Parts

PartPurposeTry it
sizePage sheet size such as A4 or landscapeTry it
marginOuter page margins for printTry it
:first / :left / :rightTarget specific pages in a print sequenceTry it

CSS Examples

A4 with margins

example.css
@page {
  size: A4;
  margin: 2cm;
}
Try It Yourself

Landscape sheets

example.css
@page {
  size: landscape;
  margin: 1.5cm;
}
Try It Yourself

Browser Support

@page is a modern CSS at-rule.

✓ Modern CSS

@page

Check current browsers before relying on advanced behavior.

90% Modern browsers
Google Chrome Recent
Full support
Mozilla Firefox Recent
Full support
Apple Safari Recent
Full support
Microsoft Edge Recent
Full support
@page Modern support

Bottom line: Use progressive enhancement. Keep a readable fallback when a browser ignores the at-rule.

Frequently Asked Questions

The printed page box: size, orientation, and margins.
No. It applies to paged media such as print and print preview.
Yes. Use @page :first, :left, and :right for page-specific rules.
Open the browser print dialog or print preview.
Widely supported for basic size and margin; advanced descriptors vary.

Next: @property

Continue with @property.

@property tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful