{"id":145,"date":"2008-06-04T08:00:25","date_gmt":"2008-06-04T13:00:25","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=145"},"modified":"2008-06-04T08:00:25","modified_gmt":"2008-06-04T13:00:25","slug":"default-print-stylesheet-template","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/default-print-stylesheet-template\/","title":{"rendered":"A Default Print Stylesheet Template"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/06\/printcss-400.gif\" alt=\"\" width=\"400\" height=\"130\" class=\"alignnone size-full wp-image-147\" \/><\/p>\n<p>A print style sheet is an extremely useful thing to have around. Most modern websites don\u2019t look all that attractive when printed using the site\u2019s default CSS: overly-large widths, screen-friendly fonts, and creative color choices all work together to make most sites less than useful on the printed page. But with a print CSS file, you can alleviate those problems and present your users with a useable, useful print alternative to your digital masterpiece.<\/p>\n<p>There can probably never be a  true \u201cboilerplate\u201d print style sheet, something you can just apply to every website you create and be done &#8212; believe me, I\u2019ve been trying to develop one for quite some time! However, this tutorial and accompanying <a href=\"\/example\/default-print-css\/print.css\">downloadable template<\/a> should help you on your way to building your own personally customized print CSS. And for some sites, it may not require any customization at all!<\/p>\n<p>To start out, we\u2019ll set some default widths, margins, floats, and backgrounds on our major elements:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">body, #content, #container {\n\twidth: 100%;\n\tmargin: 0;\n\tfloat: none;\n\tbackground: #fff url(none);\n}<\/pre>\n<p>How many times have you printed a website only to find the right third of the page was missing? Setting the width to 100% on these elements ensures they\u2019ll never extend beyond the confines of the printed page. Setting a margin of zero ensures that our content hugs the default page margins \u2013 you can add more space here if you\u2019d like. Setting our float to \u201cnone\u201d helps get around some old-school print bugs, wherein floated objects weren\u2019t printed beyond the first page. And setting our background to a default white with no image is just good printing karma \u2013 why waste your users\u2019 ink on screen-centric niceties?<\/p>\n<p>Next, we\u2019ll remove any elements that aren\u2019t needed on the printed page:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">#topnav, #navbar, #nav, #sidebar, .ad, .noprint {\n\tdisplay: none; \n}<\/pre>\n<p>Here, I\u2019m suggesting that navigation, sidebars, and ads needn\u2019t be printed. You can add to and remove from this list as your needs require. It also wouldn\u2019t hurt to create a catch-all class (like .noprint) for individual elements you\u2019d rather not be rendered on the printed page.<\/p>\n<p>We should also set some default body font faces, sizes, and colors:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">body {\n\tfont: 1em Georgia, \"Times New Roman\", Times, serif;\n\tcolor: #000; \n}<\/pre>\n<p>I\u2019m setting the font-size here to 1em in order to keep the font size flexible. If you specify a point size (say, 12pt) or a pixel size, users won\u2019t be able to use the \u201cscale\u201d functionality built into most modern browsers, which would make your pages less usable overall. <\/p>\n<p>I\u2019m also specifying a serif font for my print pages. Some argue that you should stick to whatever font you use on the screen for the sake of brand consistency, but I\u2019d argue that you can develop screen brand consistency, <em>and<\/em> a separate print brand consistency. And if you\u2019d like to interweave the two, consider using a serif font for your screen headlines and a sans-serif font for your body text, then simply reversing the font families on the printed page.<\/p>\n<p>And finally, I\u2019m setting the default text color to black. Your low-contrast design may look killer on the screen (who am I to judge?), but contrast is the name of the game on the page if you want your text to be legible.<\/p>\n<p>Next up, we\u2019ll style our headings:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">h1,h2,h3,h4,h5,h6 {\n\tfont-family: Helvetica, Arial, sans-serif;\n\tcolor: #000;\n}\nh1 { font-size: 250%; }\nh2 { font-size: 175%; }\nh3 { font-size: 135%; }\nh4 { font-size: 100%; font-variant: small-caps; }\nh5 { font-size: 100%; }\nh6 { font-size: 90%; font-style: italic; }\n<\/pre>\n<p>I\u2019m specifying a default font-family as well as a color (black again) for all of my headlines. Then, I\u2019m styling each headline uniquely so that they stand out hierarchically on the printed page. Most websites don\u2019t actually use six levels of headings, so you can change these around and eliminate lines to suit your needs.<\/p>\n<p>And finally, we need to ensure that hyperlinks are usable in print:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">a:link, a:visited {\n\tcolor: #00c;\n\tfont-weight: bold;\n\ttext-decoration: underline; }\n#content a:link:after, #content a:visited:after {\n\tcontent: \" (\" attr(href) \") \";\n}<\/pre>\n<p>The first set of rules sets our links to be dark blue, so they show up as blue on color printers and a dark grey (but not black) in grayscale. We\u2019ve also made them bold and underlined them to ensure they stand out from the rest of the page.<\/p>\n<p>But what good is highlighting your hyperlinks on the page? It\u2019s not like anyone can follow them, right? Well, that\u2019s mostly true. But by using a little advanced CSS magic, we can make the anchor tags on your page a lot more useful. Using the :after pseudo-class and the content property, we can actually <em>append<\/em> the achor\u2019s href to our hyperlink text. Now your users will be able to distinguish your links from the rest of your text, and even \u201cfollow\u201d them (albeit manually) if they\u2019d like. This trick doesn\u2019t work in Internet Explorer, sadly&#8230; but it doesn\u2019t do any harm to have the rule in there for the browsers who can use it.<\/p>\n<p>And there you have it! A default print stylesheet template. <a href=\"\/example\/default-print-css\/print.css\">If you\u2019d like to download a copy to use, just click here (right-click and save as).<\/a> Of course, this solution would work a lot better with a bit of customization, so feel free to change it up as you see fit.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Most modern websites don\u2019t look all that attractive when printed using the site\u2019s default CSS: overly-large widths, screen-friendly fonts, and creative color choices all work together to make most sites less than useful on the printed page. However, this tutorial and accompanying downloadable template should help you on your way to building your own personally customized print CSS. [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/default-print-stylesheet-template\/\" title=\"Click to read 'A Default Print Stylesheet Template'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[191],"tags":[249,327,363],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/145"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/145\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}