HTML and CSS Reference
In-Depth Information
Setting Page Margins
Although it's not currently possible to set the size or orientation of the printed page, you can—and should—set
the page's margins. You do this with the
@page
rule.
The @page Rule
The
@page
rule accepts only the
margin
shorthand property or the individual margin properties. Moreover,
you cannot use
em
or
ex
units to specify the size of the margins. Use either percentages or the physical units of
measurement in Table
16-2
.
Table 16-2.
Physical Units of Measurement for Print Styles
Unit
Description
in
Inch (2.54 centimeters)
cm
Centimeter (0.394 in)
mm
Millimeter (0.039 in)
pt
Point, a typographical unit equivalent to 1/72 of an inch (0.353 mm)
pc
Pica, a typographical unit equivalent to 12 points (4.233 mm)
To add a one-inch margin all around a page (the same as a default document in Microsoft Word), put the
following rule at the top of your print styles:
@page {
margin: 1in;
}
The following does the same using metric measurements:
@page {
margin: 2.54cm;
}
If you come from a print background, you might prefer this:
@page {
margin: 6pc;
}
■
Technically speaking you can also use
px
, which is equivalent to
0.75pt
(1/96 in or 0.265 mm).
However, the physical units in Table
16-2
are more common for print, especially fonts, which are measured in points.
Note
If you specify the margins as percentages, the left and right margins are relative to the width of the page, and
top and bottom margins are relative to its height.