CSS Design: Going to Print

by Eric Meyer

109 Reader Comments

Back to the Article
  1. Great article. Had experimented with this but now I can eliminate the print-friendly page.
    Anyone know when page-break-inside will be supported? Can’t find anything on this, although it’s in CSS2 it’s is not supported anywhere. Page-break-before and after seem to work.

    Copy & paste the code below to embed this comment.
  2. I am trying to use your example css on my company test site, but am having problems with the margin, the left margin in particular – it’s half-a-page wide, no matter which browser I print from, no matter what I set the margin percentage to, it just will not print to the left margin of the pager. Too weird. I ‘ve tested in IE6, Netscape7, Mozilla 1.1 and Opera 5 and 6. Then after that gets resolved there is the font size issue…

    Copy & paste the code below to embed this comment.
  3. My Printer wont print out!!!!1 the green light keeps flashin!!!!!!!!
    Ive changed the ink & its as defoult printer , Any ides Plz

    Copy & paste the code below to embed this comment.
  4. my printer wont print the green light keeps flashing green!!iv,e changed the ink & its as default printer . any ideas thankx

    Copy & paste the code below to embed this comment.
  5. I never realized that you CSS affects print quality so much.

    We were getting complaints from our client about the print versions of our pages.

    Until now we didnt know the cause.

    Please keep up the good work.

    Copy & paste the code below to embed this comment.
  6. So I’ve got the whole print css thing working, I can’t believe I never thought of this. :) Now I know you can set the page to print landscape or portrait, but with the footer, is there a way to make sure that it is always a the bottom of a page that I print, even if there is a lot of blank whitespace?

    Copy & paste the code below to embed this comment.
  7. I tried my pages in print preview with IE6 and found that only the active tab’s content is displayed. I used javascript to change visibility / display of other content divs, but I have a print sheet:

    div.tabs{display:none;}
    html body div.content{display:block !important;visibility:visible !important;}
    #nav{display:none;}
    title{font:20px bold sans-serif}

    No problem in Moz: I see the page displayed in print preview just like I want to see it. I linked the stylesheed in the head of my document, like this:

    <link rel=“Stylesheet” type=“text/css” media=“Print” href=’/stylesheet/print.css’ charset=“iso-8859-1” />


    You can see just about any page on my site to experience this. Here’s one:
    http://dhtmlkitchen.com/dhtml/ui/tooltip/

    Copy & paste the code below to embed this comment.
  8. Great article! I used it to create print and screen stylesheets – great results. Question: when updates are made to some pages, I change the BGCOLOR to “highlight” them. How can I preserve that effect in the print version? I have tried BODY {
    font-size: 10pt;
    background: inherit;
    background-color: inherit;
    }
    but had no luck. Thanks!

    Copy & paste the code below to embed this comment.
  9. I am learning to use CSS as much as possible. I link a single CSS file to a site with a straight forward link to the pages within the site.

    Q. The CSS shown for printing pages give reference to page options which are already taken care of for the page ‘look’. How do I link to the print page CSS without affecting the main site/page CSS?

    Do you have a print button/text which is somehow linked to the print page CSS?

    Thank you for any help you may be able to offer

    Andy

    Copy & paste the code below to embed this comment.
  10. Awesome article! I have definate need of being able to print web pages from our intranet. I’m fairly new to CSS, so what is happening when you included “!important” in your float definition for #wrapper or #content? It’s not a comment (\* , *\), right?

    #wrapper, #content {
    width: auto;
    margin: 0 5%;
    padding: 0;
    border: 0;
    float: none !important;
    color: black;
    background: transparent none;
    }
    Help?

    Copy & paste the code below to embed this comment.
  11. Yep.

    Copy & paste the code below to embed this comment.
  12. A colleague has the problem of putting headers and footers on pages when printed out. I referrred him to this article, but that particular feature doesn’t seem to have been mentioned. I intend to dig into my css reference books, since css isn’t my main specialty, I thought I ask for pointers. Anyone?

    Copy & paste the code below to embed this comment.
  13. i use a xerox docuprint 4508. all the lights are flashing eg paper jammed. paper empty etc and it will not print. obviously the paper is not the problem yet this message flashes on screen also, printer out of paper, can some one advise… anne

    Copy & paste the code below to embed this comment.
  14. Im trying to print some white text on top of an image. The approach is a simple image, and a layer positioning the white text on top of the image.

    I have a stylesheet with a screen and print type, and i can see that the print version is used.

    However, no matter how i put it, once my text color reaches a certain “lightness”, it starts fading towards grey instead of white. Pure white will produce grey.

    If i make a pure green, it will print pure green. Taking that same color and adding a little red and blue into it will have it gradually fade to grey instead of white on print.

    Anyone have a solution to this?

    Copy & paste the code below to embed this comment.
  15. I recently replaced ink cartridges (on my Canon S750 printer) and I can no longer print e-mail. It will print when I highlight, “Copy” and “Paste” the subject onto “Write”. I was able to always print out e-mail or whatever from it’s original display prior to the ink replacement. What did I do wrong?
    Thanks for any help.

    Copy & paste the code below to embed this comment.
  16. Someone asked about !important. I hadn’t remembered seeing that before either. It is explained here: http://www.w3.org/TR/REC-CSS1#important

    Basically, if I understand it correctly, by adding !important to a style, that style is forced to take precedence even when another style may normally take precedence by default. So by adding !important to a style that is absolutely necessary (for printing in this case) we do not have to worry about it being overridden by, say, a style defined within the body of the doc. (Could this be a solution to a few problems some have mentioned here?)

    Btw, the above reference is only part of a section which explains how one style gets preference over another. The entire section 3 may be helpful to anyone that is not sure how this works.

    Hope this helps.

    Copy & paste the code below to embed this comment.
  17. Some have taken issue with the lack of a printer friendly link when utilizing this solution. Some workarounds have been addressed by others. If you must you can still create such a page, although I like the suggestion to use some very simple javascript to simply print the current page.

    However, in my experience, the average user often overlooks the printer friendly link and complains that pages do not print in such a way that they are readable, thereby negating the value of the option. This alleviates that problem by ensuring that all pages look as intended when printed, no matter the level of the user (which makes it the best solution in my view). And if you feel obligated to provide the link for the more knowledgable/ observant, then by all means do.

    Thank you ala for providing another great article (to bad I didn’t read it sooner). Even the least intelligent of visitors to my sites can get the intended results whenever I follow your excellent advice.

    Copy & paste the code below to embed this comment.
  18. This was a great article, as have been all the ones I’ve read here. But I still have a question about something that’s happening to a site I’m working on. If you go to this page http://www.sassllc.com/index.asp and do a Print Preview, it looks OK. But if you go to http://www.sassllc.com/FAQ.asp and do the same, the text gets squeezed to the left of the content box.

    Am I missing something really obvious?

    Thanks so much! (If there’s a more proper place for me to be asking this, please let me know and I will forthrightly comply!)

    Copy & paste the code below to embed this comment.
  19. Hi, im new at css and i need this. I want a print this button on my page so im gonna have that link to a new page and i wanna put in this code to make it printer ready.. Now if anyone has any better ideas i would like to know :). But i dont really understand this code, well some of it. Could someone, very simply, tell me exactly where i need to put everything and what i need to change. Thanks!

    Copy & paste the code below to embed this comment.
  20. Its me again, same guy as before. Ok say i already have a style sheet on my page, because i already do. This will still work with it right?? Another question is, does this only make the printed page come out different it doesnt make it on the net look different??? I need to know how to use this because im very new at css and this is complicated, ahhhhh. By the way, i want to also make a print this icon. How would i make that work so it automatically printed?

    Copy & paste the code below to embed this comment.
  21. Great article and making me change how our new site is formatted. However…
    Like someone else in this thread I have menus on the left and removing them with display: none just leaves a blank space with the content still shifted across the page.
    How do I get the content back to use the empty space to the left?

    Thanks in anticipation.

    Copy & paste the code below to embed this comment.
  22. I’ve used the similar
    http://alistapart.com/stories/alternate/
    alternate CSS to create a fixed point font size for printing. But both on that, and also your sample page, my IE6 continues to print as if the screen font is not changed. (NN6 is fine though). In other words, IE6 completely disregards the visible changes on the screen, although it DOES print out according to size if I use the mousewheel to resize the print.

    Is this a known Win IE6 problem? Is it my setup? Is there any way round it?

    Many thanks

    Tony

    Copy & paste the code below to embed this comment.
  23. I cannot get the display: none to work. I’m using IE 6.0 to view my pages. I see it working on the article’s page but it isn’t working on mine. Ugh!!!!

    Copy & paste the code below to embed this comment.
  24. Very good article, I use tricks that explain and everithing works fine!

    Copy & paste the code below to embed this comment.
  25. Try {display: none !important;}

    Copy & paste the code below to embed this comment.
  26. Hi,

    First, thank you for a very good idea on print style sheets. I am a complete novice at this CSS thing so please be kind if the idea I’m about to suggest is flawed.

    I created a separate print style sheet as per the article and added it to my template with the following declaration:

    <style type=“text/css” media=“all”> import &#8220;styles.css&#8221;; &lt;/style&gt; <br /> &lt;link rel=&#8220;stylesheet&#8221; type=&#8220;text/css&#8221; media=&#8220;print&#8221; href=&#8220;print.css&#8221; /&gt; <br /> <br /> But I found that when I validated the CSS by URI it did so but the validator gave me warnings saying that I had several redefinitions in my CSS. Obviously the W3C validator reads both style sheets and adds them together, I don&#8217;t know. So I searched for a hack and couldn&#8217;t find anything until I came across the media tag.

    Within my style sheet (styles.css) I added the following:

    @media print {

    /* I then cut and pasted my print style sheet into this section */

    }

    It worked great and validated correctly, naturally that meant I could remove the line.

    <link rel=“stylesheet” type=“text/css” media=“print” href=“print.css” />

    So now I have a single style sheet that does two jobs. Some of you gurus may already know about this technique but I thought I’d share it anyway, plus someone may be able to develop it further.

    regards,

    Terry

    Copy & paste the code below to embed this comment.
  27. While I find the solution discussed in this article interesting, sometimes you want to offer visitors more than just the same page with different looks.

    Is it possible to instruct the web browser to choose a specific document when the user wants to print a page? Something like
    <link rel=“printable” href=“resume.pdf” />
    that basicallt says: “if the user wants to print this page, use the document resume.pdf”.

    Copy & paste the code below to embed this comment.
  28. This is a great article but I’m working with a site currently built with tables. Most of the code has worked (getting rid of graphics, changing fonts, etc.), but my text is being cut off by the right margin of the printed page. I’m not sure if this is b/c of tables or some other problem. The content is the center column of a three column table. Left and right columns are set to display:none. Any ideas?

    Copy & paste the code below to embed this comment.
  29. I printed this article in Safari 1.0 (v85) and the main content wrapped to a column only about 25% the width of the page. From IE, it looked fine. Is there a something in the CSS that can fix this? Or perhaps it’s a browser-bug?

    Copy & paste the code below to embed this comment.