This site is designed for accessibility. Content is obtainable and functional to any browser or Internet device. This site's full visual experience is available in a graphical browser that supports web standards. Please consider upgrading your web browser.

Print Style Sheets

Introduction

When a web page is printed without it's own print style sheet it comes out pretty much as it appears on the screen. Fine, but would that be the most appropriate appearance for the content that it is being printed, and then presumably read from that printed page? If you think about it, no is the correct answer. Take a look at some of the aspects of the appearance of the page on-screen and you'll see what I mean.

Paper is different than pixels

The most basic thing is the font and its size. Think about the font itself. This has been set to

font-family: Verdana, Helvetica, Arial, sans-serif

because sans-serif fonts are the best fonts to use for ease of on-screen reading. Verdana was actually created specifically for this purpose. If your main contact with design has been creating content to be read on-screen, you probably use Verdana or another sans-serif font for all body text purposes. But if you use it for materials that are going to be printed out, even on a quite low resolution printer, let alone a laser printer, you are dead wrong. Those who in fact come from a "real world" design background will almost certainly know that serif fonts are the correct choice for body text on a printed page.

Why the difference? It's a good question that I can't resist answering. Serif fonts work best on paper because the serifs on the letters help tie all the letters in a word together and create the recognizable word entities (as opposed to a group of individual letters) that we use when we are reading. Sans-serif fonts don't have this legibility aid. So why then don't we use serif fonts on-screen? The answer lies in resolution. Pages will be printed, at the barest minimum of 150 dpi, and more likely 300 dpi on a laser printer. Screens on the other hand are struggling to get to 96 dpi, and the most you can rely on is 72 dpi. This simply isn't enough to recreate the subtlety of serif fonts with any accuracy. Instead, the approximation it gives is somewhat messy and more difficult to read. The advantage of the serif is far outweighed by its disadvantage in this context.

So, if we were planning to have our page printed, for maximum legibility we would specify a collection of serif fonts, maybe something like

The size of the font would be different as well. We don't generally speak about ems when we are talking about printing something - instead we talk about points. If we were going to print our page we would probably specify a font-size of perhaps 12 or 14pt.

Another convention that differs between printed and on-screen materials is justification of the text. Generally in printed matter it is better to have text which is fully justified, rather than the left justified, "ragged right" text we usually see on-screen. We could change that as well.

Color and (less so) images are "cheap" on-screen. It doesn't cost more money to have an attractively colored background on your page as we've done here, and the images we have included are small, so cost relatively little in terms of download time. Color on paper is a different story. Color costs money to print, and the more color you have the more money it costs. We'll like it easier for people to print our pages if we remove the images and the decorative background.

And we might like to change the layout of the page, making it simpler and allowing a lot more text to fit on the page than it does at the moment. As well we'll probably want to change some of the style for the various heading levels and get rid of a lot of of the use of color.

The Cascade in a Print Style Sheet

The cascading cascading part of cascading style sheets becomes important in a print stylesheet. All the properties specified in your default stylesheet will cascade into print stylesheet (even when it is being printed) provided nothing in print stylesheet changes or cancels their effect. If you want a property to be the same in both the on-screen version and the printed version of the page, you don't have to worry about it at all in print stylesheet. If you don't do anything to override it, it will continue to have the same effect. But if you want a difference style in your style sheet be sure to consider the cascade. Declaring properties explicitly works much of the time.

Some Helpful Properties

The Display Property

To get rid of the images in the printed version of a document use the display property. The display property is a relatively advanced property which allows you to change how an element is displayed in the browser. The values include,

The display property is probably best explained by looking at some of the values it can take along with some elements that inherently have that value.

Printing Specific Properties

In CSS there are a number of properties you can use which will have their specific effect when your page is printed. If you've done any work in desktop publishing you'll be aware that it's vital to have control over where a page will and will not break, for example, when it is being printed. While these properties are not universally supported in all browsers, they cause no harm in browsers that don't support them, so you may as well use them particularly if you have an eye to the future.

The two most simple to understand, and widely supported page-breaking properties are:

These two can both take a number of quite sophisticated values, but those you'll be most interested in initially are:

Again, if you've worked in desktop publishing you'll see how these properties and values are analogous to properties you set up in styles. For instance you could use:

h1, h2, h3 {
page-break-after: avoid;
}

The 'content' property, in conjunction with the :after pseudo-element

The :after pseudo-element may be useful in a print stylesheet for generating content of a URI, abbreviation or acronym. For instance you could use:

a:after {
content : " (" attr(href) ") ";
}
abbr[title]:after , acronym[title]:after {
content : " (" attr(title) ") ";
}

An Example

I might go about creating a print a stylesheet by writing something like:

body {
color : black;
background : white;
font-family : "Times New Roman", Times, "New York", serif;
}
p {
margin : 0;
text-indent : 3em;
}
h1 , h2 , h3 , h4 , h5 , h6 {
font-family : verdana, arial, helvetica, sans-serif;
margin-top : 1.5em;
}
h1 , h2 , h3 {
border-bottom : 1px solid black;
}
h4 , h5 , h6 {
border-bottom : 1px solid gray;
}
a:link , a:visited {
text-decoration : underline;
color : black;
background : white;
}
abbr[title]:after , acronym[title]:after {
content : "(" attr(title) ")";
}
.noprint {
display : none;
}

...and so on, making changes and previewing them in my browser. Once I had the stylesheet tweaked to my satisfaction, then I'd make one simple change:

<style type="text/css" media="print">

In the meantime, while styling for print, I'd want to make sure I didn't have the actual screen-media styles interfering. So let's say that I had a screen-media stylesheet in the document. Before I started work on my print styles, I'd edit it to only apply to a medium like tty or aural-- something I knew my browser didn't support. Then, once I'd switched my print styles to actually have media-"print", I'd switch the tty value back to screen.

Remember this, the default value of media is all. So if you don't give a stylesheet a media value, it will be applied to your printouts as well as the screen display.