The page model specifies how a document is
formatted within a rectangular area -- the page
box -- that has a finite width and height. The page box is an abstract rectangle that does not
necessarily correspond to the sheet where the document will ultimately be rendered
(paper, transparency, screen, etc.).

The CSS page model specifies formatting in the page box, but it is
the user agent's responsibility to transfer the page box to the
sheet. Some transfer possibilities include:

Transferring one page box to one sheet (e.g., single-sided printing).

Transferring two page boxes to both sides of the same sheet (e.g.,
double-sided printing).

Printing signatures (a group of pages
printed on a sheet, which, when folded and trimmed like a book, appear in their
proper sequence).

Printing one document to several output trays.

Transferring to a file.

This document does not specify how user agents transfer page boxes
to sheets. It does allow users to provide the user agent (often
through a dialog box) with information about the size of the sheet and
the orientation of the transfer (see the 'size' property).

The following sections explain page formatting in CSS2. Four
properties indicate where the user agent may or should break pages,
and on what page (left or right) the subsequent content should resume.
Each page break ends the current page box and begins the next.

These properties have been designed to support the PRINT
medium, but can also be applied to other paged media, for example PROJECTOR medium.

In the vertical margin between block-level elements. When a page
break occurs here, the margin disappears (becomes zero).

Between lines inside a block-level element.

These breaks are subject to the following rules:

Breaking at (1) is only allowed if the 'break-after' and 'break-before' properties of all
the elements that meet at this margin allow it, which is when at least
one of them has the value 'always', 'left', or 'right', or when all of them are
'auto'.

Breaking at (2) is only allowed if the number of lines between the
break and the start of the block is 'orphans' or more, and the number of
lines between the break and the end of the block is 'widows' or more.

There is an exception to both rules:

Breaking at (1) and (2) is also allowed if, between the last page break
and the next one that would be allowed under (A) and (B), there is so
much content that it can't fit on a page.

A page break must occur at (1) if, among the 'break-after' and 'break-before' properties of all
the elements that meet at this margin, there is at least one with the value
'always', 'left', or 'right'.

CSS does not define which of the page breaks allowed by
(A), (B), or (C) should be used. In particular, CSS does not forbid a
UA from breaking at every possible break point, or not to break at all. But
CSS does recommend that UAs observe the following heuristics (while
recognizing that they are sometimes contradictory):

Break as few times as possible.

Make all pages that don't end with a forced break appear to have about
the same height.

Avoid breaking inside a block that has a border.

Avoid breaking inside a table.

Avoid breaking inside a floating element

Suppose, for example, that 'orphans'=4, 'widows'=2, and
there are 20 lines available at the bottom of the current page:

If a paragraph at the end of the current page contains 20 lines or fewer,
it should be placed on the current page.

If the paragraph contains 21 - 22 lines, the second part of the
paragraph must not violate the 'widows' constraint, and so the
second part must contain exactly two lines

If the paragraph contains 23 lines or more, the first part should
contain 20 lines and the second part the remaining lines.

Now suppose that 'orphans'=10,
'widows'=20,
and there are 8 lines available at the bottom of the current page:

If a paragraph at the end of the current page contains 8 lines or
less, it should be placed on the current page.

If the paragraph contains 9 or more lines, it cannot be split
(that would violate the orphan constraint), so it should move
as a block to the next page.

CSS2 allows authors to specify the dimensions of the page box, the
margins, and several other properties relative to each page. However,
since some document languages (e.g., HTML) do not define elements that
represent "the page", these properties are specified for an entire
document via the @page
rule.

For example, the following @page rule sets the margins of the page to 2cm.

@page { margin: 2cm }

Declarations inside the curly braces of the @page rule apply to
every page of a document. These declarations are said to be in the
page
context, and they describe the page
box into which the elements of the document are flowed according
to the page model.

The page context allows the 'size' property to set the size of the
page box and the 'marks' property
to set crop and cross marks.

The CSS2 rules for collapsing vertical
margins apply to page margins as well. For example, the margin of
the first element box on a page will collapse with the page margin.

The page context has no notion of fonts, so 'em' and 'ex' units are
not allowed. Percentage values on the margin properties are relative
to the dimensions of the page box. All other units associated with
the respective CSS2 properties are allowed.

Due to negative margin values (either on the page box or on
elements) or absolute
positioning content may end up outside the page box, but this
content may be cut -- by the user agent, the printer, or ultimately
the paper cutter.

The size of a page box may either be "absolute" (fixed size) or
"relative" (scalable, i.e., fitting available sheet sizes). Relative
page boxes allow user agents to scale a document and make optimal use
of the target size. Absolute page boxes ensure precise formatting when
that is the author's prerogative.

The page box will be set to the size and orientation of the
target sheet. This is the initial value of the property.

@page {
size: auto;
margin: 10%;
}

In the above example, the outer edges of the page box will align
with the target. (Since 'auto' is the initial value on 'size', it is normally not necessary to
set this value.) The percentage value on the 'margin' property is relative to the
target size so if the target is 21.0cm x 29.7cm (i.e., A4), the
margins are 2.10cm and 2.97cm.

landscape

The page box will have the same size as the target, and the normal
direction of print occurs across the largest dimension of the target.
Thus, the target orientation will be ignored.

portrait

the page box will have the same size as the target, and the normal
direction of print occurs across the shortest dimension of the target.
Thus, the target orientation will be ignored.

Explicit length values for the 'size' property create an absolute page
box. If only one length value is specified, it sets both the width and
height of the page box (i.e., the box is a square). Since the page box
has no "parent", percentage values are not allowed on the 'size' property.

For example:

@page {
size: 8.5in 11in; /* width height */
}

The above example set the width of the page box to be 8.5in and the
height to be 11in. The page box in this example requires a target
size of 8.5"x11" or bigger to be printed.

User agents may allow users to control the transfer of the page
box to the sheet (e.g., rotating an absolute page box that's
being printed).

Rendering page boxes that do not fit a target sheet

If page box does not fit the target sheet dimensions, the
user agent may choose to:

Rotate the page box 90° if this will make the page box fit.

Scale the page to fit the target.

The user agent should consult the user before performing these
operations.

When the page box is smaller than the target size, the user agent
is free to place the page box anywhere on the sheet. However, it is
recommended that the page box be centered on the sheet since this will
align double-sided pages and avoid accidental loss of information that
is printed near the edge of the sheet.

Note.
Typically, 8.5"x11" sheet size will be available in North
America, while printers in other parts of the world are more likely to
have the A4 sheet size available.

In high-quality printing, various marks are often added outside the
page box. Crop
marks indicate where the page should be cut and cross marks
(also known as register marks or registration marks) are used to align
sheets. This property describes what marks should be printed on the
page outside the outer edges of the page box.

Marks are only visible on absolute page boxes. In relative page
boxes, the page box will be aligned with the target and the marks
will be outside the printable area.

The size, style, and position of cross marks depends on the user
agent.

If different declarations have been given for left and right pages,
the user agent must honor these declarations even if the user agent
does not transfer the page boxes to left and right sheets (e.g., a
printer that only prints single-sided).

Whether the first page of a document is :left or :right depends on
the major writing direction of the document and is outside the scope
of this document. However, to force a :left or :right first page,
authors may insert a page break before the element at the top of the
document tree (e.g., the HTML element in HTML).

Note.
Adding declarations to the :left or :right pseudo-class does not
influence whether the document comes out of the printer double- or
single-sided (which is outside the scope of this specification).

Note.
Future versions of CSS may include other page pseudo-classes (e.g.,
:first).

It is customary in printed documents to put navigation aids at the
top and/or bottom of the page. Often you'll find a page number, the
name of the book, and the title of the current chapter there.

CSS defines two areas of the page for holding this kind of
information. They are referred to as the :header and :footer pseudo-elements, since their default
position is above (resp., below) the content of the page. Their content
and other properties are defined inside an @page rule:

The cascading rules determine what the
values for properties are in case the same property is set on various
@page rules. The specificity of @page is 0, every :left, :right,
:footer, and :header adds 1 to the specificity.

The :footer and :header areas behave very similar to 'fixed' elements. The only
difference is in their content: in headers and footers the content is
limited to one line, and it may vary from page to page, since it can
include variables. The page content is the reference box for the header and
footer. See section "fixed
positioning" for a description of fixed elements.

The initial values for 'top',
'bottom' and 'height' are different for :footer and
:header than for normal fixed elements:

'top' in :header has a UA-dependent initial value. A suggested
value is -3em.

'bottom' in :footer has a UA-dependent initial value. A
suggested value is -3em.

'height' in both :header and :footer has a UA-dependent initial
value. A suggested value is 1em.

The suggested values make the header and footer as wide as the page
content, and about two lines above (resp., below) it.

The content of the header and footer is specified with the 'content' property. The content is
always rendered as a single line. (If the content is too long, the UA
should cut it off in some way.) The value is a comma-separated list of
1, 2, or 3 values. Depending on the 'direction' property, the first of
these is left- or right-aligned, the second is centered, and the third
is right- or left-aligned.

The content is a concatenation of fixed strings and variable
parts. The following variable parts are allowed:

X can be one of 'title', 'chapter', or
'section'. First(X) expands to the content of the first
element on the page that has a 'running-head:X'
property. If there is none, 'first()' is the same as
'previous()'. 'Last(X)' expands to the content of the last
element on the page with a 'running-head:X property. If
there is none, 'last' is the same as
'previous'. 'Previous(X)' expands to the contents of the
last element with 'running-head:X' on all pages before this
one. If there is none, the result is the empty string.

url

This expands to the URL of the document (not of the style sheet).

date

This expands to the current date, in the user's locale and format.

The "contents" is the text content of the element and all its
children, excluding the content of elements that have 'display:none'.

This example creates two running headers, the one on the left page
has a page number on the left, and the content of the first element
marked as 'chapter' on the right. The right header has the content of
the last element marked as 'section' on the left and the page number
on the right. Both headers are in 10pt small-caps.

The value 'none' means that the element is not marked. 'Title',
'chapter' and 'section' say that the element is marked as a title,
chapter or section, resp. and that the content can be used in the
running header or footer.

This style sheet marks H2 elements as 'chapter' and DT elements as
'section'. This can be used, e.g., in combination with the running
headers of the previous example.

When formatting content in the page model, some content may end up
outside the page box. For example, an element with 'white-space: pre'
may be wider than the page box. Also, when elements are positioned
outside the flow model, they
may end up in inconvenient locations. For example, images may be
placed on the edge of the page box or 100,000 inches below the page
box.

A specification for the exact formatting of such elements lies
outside the scope of this document. However, we recommend that authors
and user agents observe the following general principles concerning
content outside the page box:

Content should be formatted slightly beyond the page box to allow
pages to "bleed".

User agents should avoid printing large numbers of blank pages to
honor positioning of elements. Note, however, that printing small
numbers of blank pages may be necessary to honor the 'left' and
'right' values for 'page-break-before' and
'page-break-after'.

Authors should not position elements in inconvenient locations
as a means to avoid printing them. Authors should use the
'display' or
'visibility' properties
for this purpose.

User agents may handle elements positioned outside the page box in
several ways, including discarding them or printing them at the end of
the document.

Declarations in the page context cascade just like normal CSS2
declarations.

Consider the following example:

@page {
margin-left: 3cm;
}
@page :left {
margin-left: 4cm;
}

Due to the higher specificity of the pseudo-class selector (see the
section on cascading order
for details), the left margin on left pages will be '4cm' and all
other pages (i.e., the right pages) will have a left margin of '3cm'.