Testing CSS for print media: we need a Print Preview for developers!
— How I wish there was an easier way to test CSS intended for the printed page.”
Source: Wikimedia Commons
The virtues of @media print have been explained elsewhere, best of all by Eric Meyer in his seminal A List Apart article Going to Print, whose original publish date (May 2002) makes me feel a bit old!
Yet one of the most annoying aspects of developing CSS for print is testing it.
Now I know that testing print CSS doesn’t take a huge slice of our lives, but it annoys the heck out of me. So if you’re a tolerant sort of person who’s happy to rub along with naff workflows, you might find this article and indeed the fact that there’s a whole article on the subject, just a bit finicky.
Thing is, I hate testing print CSS.
Sure, simple markup and layouts only need buffing to a shine to be ready for print, but an increase in complexity or a requirement for absolute fidelity in printed material can lead to ugly scenes round my way.
Print CSS: browser testing !== Print Preview testing

Developers tend temporarily to substitute their screen CSS for their print CSS, run it in the ordinary browser environment, et voilà. Rinse and repeat.
Yet the actual conversion to the printed page can sometimes lead to unexpected results, as can be seen in the image: different browsers, different Print Preview results – even though in the browser there was nothing obviously objectionable.
Print Preview !== a tool for development
Finding fiddly print CSS issues would be a lot easier if testing tweaks was a smoother process. Every change cycle equates to:
- Refresh the page
- Invoke Print Preview
- Review the change
- Close Print Preview
Testing print CSS as opposed screen CSS appends two additional steps 2 and 4 – invoke Print Preview (Alt + F + V in Windows for both IE and Firefox) and close Print Preview (correspondingly Alt + F4) . Those two simple steps make the business very laborious, even if you can remember those shortcuts.
Slight workflow improvement: an IE-only trick
A dirty little script in IE only takes care of the task of invoking Print Preview, which slightly shortens the workflow. Yes, it’s IE only, but given that it’s usually IE giving me print CSS grief, every little helps:
<script type="text/javascript">
function printpr()
{
var OLECMDID = 7;
var PROMPT = 1;
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
printpr();
</script>
This script automatically invokes IE’s Print Preview. Dump it just before the </body> and save yourself a shortcut! You could also call printpr() from anywhere else, of course. And here’s the source of the original code snippet, which also shows a few other unrelated options such as Save As.
Why can’t we refresh the Print Preview?
All of which finally begs the question, why can’t we simply refresh the Print Preview with an F5 shortcut, just like we have in the browser itself?
Probably because I’m the only person in the world who gets genuinely annoyed by testing print CSS in Print Preview. More fool me, I guess.
Comments
6 responses so far to Testing CSS for print media: we need a Print Preview for developers!
Why not give me your comments?
See also:
jQuery .html() returns strange results in IE after other bindings
Sometimes we’re stuck with junk attributes in jQuery.html() for Internet Explorer.
- Originally published: 17 Feb 2009 in Technical
CSS floats: container does not stretch to fit floated contents
Here’s a quick resolution to an almost ungooglable problem.
- Originally published: 18 Jan 2006 in Technical
Graphic Designers are not Web Designers
Glad you could join us: communications agencies have finally decided that the Internet is highbrow. Hold on tight!
- Originally published: 24 Nov 2005 in Technical
Dreamweaver CS3 crashes and won’t start up again
The world famous 8,192kb bug that crashed a million Dreamweavers. Probably.
- Originally published: 1 Feb 2008 in Technical
Wrangling writers: information design and content policy
Notes on important themes in the close relationship between information design and content writing and editing.
- Originally published: 16 Feb 2010 in Information design
Who you gonna call?
Hello you, I'm Mike Padgett. I'm not a Princeton curator, Knoxville mayoral candidate, Kentuckian pastor or Arizona journalist, I just share the same name. In fact, I am a consultant working in user experience and information design.
I also enjoy travel, concerts, films and walking.
I'm originally from Yorkshire, England but nowadays I live in Belgium. My current favourite Belgian beer is Black Albert.
Shameless self-promotion
Over a year in the making, Dopeology.org is my latest personal project: a topology of doping in thirty years of European pro road cycling.
I collected information from thousands of sources, then I modelled and published it via a lightweight user interface.






August 5th, 2009 at 2:34
No, you’re not the only one. I’m knee-deep in the middle of a project with this exact same frustration. Everything you say is true, and not a browser one (that I’ve run across, err, a browser that *really matters*) has any feature set that eases the pain we feel.
The Web Developer extension for Firefox has an attempt at facilitating print media CSS development (CSS > Display CSS be Media Type…), but I haven’t gotten it to work for me. I don’t know if it’s my CSS, or the extension itself… doesn’t seem to work.
August 5th, 2009 at 7:22
Quite right, Matt, and it’s good to hear it’s not just me!
Chris Pederick’s Web Developer Toolbar does indeed have that facility, which is useful (and it works for me).
However, maybe like me you’ve also found that there are often problems that you only discover when you actually do Print Preview or print the page, such as the one you can see in the picture which can occur with floated elements.
July 22nd, 2010 at 11:15
True, the first few times you don’t mind closing, refreshing, and reopening (not to mention scrolling back to the point your checking) but after a while it becomes so annoying you find yourself reconsidering the whole project! Thanks for the tips on the extensions, but they are of no help because the print preview can be completely different from the browser view w/print stylesheet, especially if you use a multi-column layout since this restarts on every printed page, but never does in a single web page. Margins can also be an issue, and I guess a number of other things… So, I’m wondering if a FF extension could add a Refresh button or shortcut to the preview environment…?
February 21st, 2011 at 19:19
Yup.
Same deal over here – working on an event calendar that prints to a ‘fridge calendar.’
Not tough, but very, very, tedious going back and forth….
November 10th, 2011 at 23:43
Yeah, I’m missing that reload function in print preview too! I just submitted this as an “Idea for Firefox” (looks like they discontinued the Bugzilla system for submitting requests for enhancements – so people cannot vote for anything anymore :-(
December 25th, 2011 at 13:51
Yes, print preview is a chore. I usually just set up a separate print stylesheet on a development site and tweak it that way and preview across browsers. It would be great to have a comprehensive tool to simplify testing.