Print CSS Lays Out Pages Before They Reach the Printer
The edge of a page in a browser's print layout and the edge of the paper in the tray belong to different rectangles. Print CSS sets the geometry of the first rectangle, called a page box, including its size, orientation and margins. The browser has to decide how to place that layout on the physical sheet if the sizes differ, and the printer determines how close to the sheet's edge it can reliably mark.

The World Wide Web Consortium draws the distinction in its September 2023 working draft of CSS Paged Media. The draft states: "The page sheet is one surface of the physical medium." A page box belongs to the document's layout; a page sheet is the surface to which the layout is transferred. The draft describes the formatting model and recommends ways to deal with a poor fit. It does not specify exactly how software transfers a page box to a sheet. The rules below describe the model rather than the feature set of a particular browser.
Where does the document split into pages?
On a scrolling screen, the bottom of the visible window does not divide the document into separate pages. In the World Wide Web Consortium's paged-media model, the browser instead lays out the document in rectangles of finite width and height. The uninterrupted flow becomes a sequence of page boxes. The sheet can be absent at this point: that sequence is part of the formatting, before anything is transferred to paper.
The box has an interior called the page area. This is where the document's text, images and other elements go on that page. A paragraph placed in the page area is part of the document flow. It takes up space there, and any part of the flow carried across a page break resumes in the next page box.
The break ends layout in the current box. The draft refers to a separate set of CSS rules for fragmentation, the term for dividing content across boundaries such as page breaks. These rules include properties that can require or discourage a break around or inside an element. The paged-media model supplies the rectangles into which the resulting pieces are laid out.
In the draft's example of named pages, the stylesheet sends tables to a landscape layout and puts the following paragraph back into the narrower layout. The instruction travels in two parts. The page property on a table selects the page type for that element. A matching @page rule supplies the settings for that type. If a break is needed to switch types, a new page box takes over at that boundary. The draft's example allows the tables to share a page if they fit.
Suppose a short heading and the text beneath it fall near the bottom of a page. A rule discouraging a break after the heading concerns the point where the flow is divided. Widening the page box concerns the space available for the flow in the first place. Both can affect where a paragraph lands, but they are instructions about different parts of the layout.
- Page box:
- The rectangle the browser lays out for a page.
- Page area:
- The part of the page box that holds the document flow.
- Page break:
- The boundary where layout in the current box ends and the remaining flow resumes in a new box.
What can the page rule change?
The CSS rule @page supplies settings for the page box. Without a selector, a condition specifying which pages match, the rule applies to every page. A margin declaration there changes the space around the page area. The declaration does not apply directly to the document's paragraphs. A margin set on a paragraph, by contrast, belongs to that paragraph's own box.
The distinction matters even if the two settings seem to make the same white strip on paper. A page margin leaves space at the edge of the page area. A paragraph margin places space around a particular block of text in the flow. If that block lands on a different page after the document is edited, the page margin still belongs at the edge of the page, while the paragraph margin still belongs to the block.
Percentage margins illustrate the difference between the width and height of the rectangle. Under the draft's rule, horizontal percentages refer to the width, while vertical percentages refer to the height. Suppose a page box taller than it is wide gives its top and side margins the same positive percentage. The top margin is still deeper because it takes its share from the longer dimension. Equal percentages in the supplied CSS can produce strips of different thicknesses around the rendered result.
The size setting specifies the target size and orientation of the page box's containing block, the rectangle within which the box is laid out. A named paper size can be combined with landscape to ask for a wide layout. In the draft's landscape example, the width and height of the layout are switched relative to the portrait form of the named sheet. The declaration says what rectangle the browser ought to work with; it cannot put a sheet of the corresponding size in the printer.
- Supplied CSS
- An @page margin
- Landscape in the @page size setting
- Rendered result in the draft model
- Space around the area holding the document flow
- A page box with its long sides horizontal
Rotation can refer to a different operation. The draft's page-orientation setting describes turning the finished layout if the output format supports rotation. A table laid out within a narrow page stays laid out at that width when the whole page is turned. Giving that table a wider page with size can change how the table fits before any rotation takes place.
The draft treats rotation after layout as a way to handle mixed orientations when software cannot readily flow content across pages of different widths. That limitation belongs to the implementation. The two instructions describe distinct results regardless of whether a particular browser provides both: a wider space for layout, or a turn of the already completed page.
Where does the printer's own margin begin?
The World Wide Web Consortium defines the non-printable area as the part of a sheet a printer cannot mark reliably, typically near its edges. The printable area is what remains inside that boundary. The dimensions depend on the printer, and the draft notes that the browser may not know them. A stylesheet can set a page margin without having any knowledge of where the hardware's boundary falls.
Suppose an empty strip appears along the edge of a printout. In the page layout, the strip might have been deliberately left clear of document text by the margin rule. On the physical sheet, a similar strip may be beyond the printer's reliable reach. Changing the CSS can alter the first strip. It does not move the physical limit represented by the second.
The two can overlap. The working draft advises browser makers to include the non-printable area in the default page margin. Where the browser knows the size of the non-printable area, the draft also allows it to adjust formatting so content lands inside the printable region. A margin left unspecified in the supplied CSS can therefore still have a visible effect: a default margin gives the content some clearance when the document is formatted.
This boundary also explains a condition on crop marks, the short lines that indicate where a print should be trimmed. The World Wide Web Consortium puts those marks outside the page box. For the marks to be visible under the draft's model, the page box must be smaller than the printer's printable area. A sheet larger than the box is only part of the requirement; the area the printer can actually mark must leave room outside the box as well.
The draft also describes bleed, the distance that a rendering is allowed to extend outside the page box before being cut off. Suppose a block of colour is meant to reach the trim edge. Its layout can extend past that edge, but an extension in the CSS still says nothing about whether the printer can mark that part of the physical sheet.
- Crop marks: The draft places them beyond the page box to mark the trim edges.
- Printable area: The page box must be smaller than this area for the marks to show.
What happens when the page box and sheet do not match?
The World Wide Web Consortium gives the browser an order of preference rather than a single prescribed result. First comes keeping the page box at its intended size on a larger sheet. Rotation comes next if turning the page box will make it fit. Both options retain the dimensions chosen for the layout. Rotation changes the direction in which that rectangle is placed on the sheet; the larger-sheet option gives the rectangle more room without turning it.
After those options the draft lists scaling, with the proportions preserved. Shrinking a finished layout reduces the printed size of everything in it. Giving the flow a smaller page box at the outset is a different operation: it changes the room available for lines and page breaks. The scaling option in the draft starts with a page box that already exists and concerns how that result is put on a sheet.
The final alternatives are to split the graphic rendering of the page box across sheets or to clip the part that overflows. The first divides the already laid-out image of the page. The second drops the part that does not fit. Neither is the page break that sent the next piece of the document flow into a new CSS page box. The draft puts clipping last.
- Larger sheet: Keep the page box at its intended size.
- Rotation: Turn the box if doing so makes it fit.
- Scaling: Resize the box while preserving its proportions.
- Slicing: Divide the rendered box across sheets.
- Clipping: Cut off overflow as the least preferred option.
The draft also leaves room for the browser to consult the person printing. It describes a separate choice when a page box is smaller than the sheet: the browser can centre the layout or put it in a corner. A corner placement may use less of the medium. For corner placement the suggested position is the upper left, with another corner possible depending on the direction and writing mode of the document. For a double-sided printout, the draft gives centring a practical purpose: it helps the layouts on opposite sides of the sheet line up and reduces the risk of losing material near an edge.
Frequently Asked Questions
Does styling left and right CSS pages turn on double-sided printing?
Left and right page selectors assign styles to alternating types of page in the CSS layout. The World Wide Web Consortium says the paged-media module has no control for enabling double-sided printing, so the alternating layouts also apply when the sheets are printed on one side only.
Can print CSS give the first page a different top margin from the rest?
The :first page selector matches the first printed page. The draft shows a general page rule providing margins and a separate first-page rule changing only the top margin, so the first page can reserve extra space at the top without making that change throughout the document.
What can a CSS page-margin box hold?
A CSS page-margin box can contain supplementary material, such as a document title in a running header or a page number in a footer. In the draft, a margin box is generated only if its computed content, the value after CSS rules are resolved, is something other than none.
Can print CSS leave a page number on a blank page?
In the World Wide Web Consortium's draft, the :blank selector matches pages without document content that are inserted by certain forced page breaks. A blank right-hand page can match both :blank and :right. The draft shows how the blank-page rule can remove the header while the right-page rule still supplies the page number.
What makes a CSS page a left or a right page?
The starting side depends on page progression, the direction in which the pages would be placed side by side. In the draft's default sequence, a document progressing from left to right starts on a right page, while a right-to-left sequence starts on a left page.
Sources
- World Wide Web Consortium: CSS Paged Media Module Level 3
- World Wide Web Consortium: Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification: Box model