CSS | @page rule
The CSS @page rule defines the dimension of the page which is gonna be print. There are few important things should be under control when you want to print a web page those are listed below:
- The page size, orientation, margins, border, and padding.
- Page breaks.
- Headers and footers.
- Page counters.
- Orphans.
All the above things are controllable when you follow the @page rule.
Syntax:
@page [:left | :right | :first] {
/* print-specific rules */
}
Page Descriptor: There are three Descriptor in @page rule those are:
- size: Specify the size of page box’s containing block.
@page {size: A4;}chevron_rightfilter_none - marks: It helps to trim the page that you want to print.
@page {marks: crop cross;}chevron_rightfilter_none - bleed: It extend the bleed area of the box
@page {bleed: 7pt;}chevron_rightfilter_none
Example:
<!DOCTYPE html> <html lang="en"> <head> <title>CSS @page rule</title> <style type="text/css"> /* default for all pages */ @page { margin: 2in; } /* margin on left page */ @page :left { margin: 1in; } /* margin on right page */ @page :right { margin: 3in; } /* top margin on first page */ @page :first { margin-top: 5in; } h1{ color:green; } </style> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2>CSS Page At-rule</h2> <p> If you open output in a new window and print the page the margin around the text content appears differently than it appears on the screen. </p> </center> </body> </html> |
Output: When you choose to print the output screen of the above code.

Supported Browsers: The browsers supported by CSS @page rule are listed below:
- Google Chrome 2.0
- Interenet Explorer 8.0
- Safari 5.1
- Opera 6.0
Recommended Posts:
- How to display search result of another page on same page using ajax in JSP?
- How to redirect a page to another page in HTML ?
- How to show Page Loading div until the page has finished loading?
- CSS | @keyframes Rule
- What does the CSS rule “clear: both” do?
- CSS | @import rule
- CSS | @charset Rule
- CSS | @media Rule
- CSS | column-rule Property
- CSS | @font-face rule
- CSS | column-rule-width Property
- How to read CSS rule values with JavaScript?
- CSS | column-rule-style Property
- CSS | column-rule-color Property
- ES6 | Page Printing
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



