Morshed Alam
Morshed Alam Software Architect

How to prevent print a block of an HTML page?

• By Morshed Alam • Security
Sometimes you may need to prevent printing a block of an html page. You can do it easily. Create a CSS class by following way and add it to your header section:
<style type="text/css" media = "print">
.noprint{display: none;}
</style>

Note that the media of the css script will be print. Now simply add the css class noprint to any elements in your HTML which you do not want to printed.

Below is the sample example to prevent printing a block:
<html>
<head>
<title>Prevent to printing a block of an html</title>
<style type="text/css" media = "print">
.noprint{display: none;}
</style>
</head>
<body>
<div>
<div class="noprint">This is the sample block which will not print...</div>
<div><h3>This is the sample text which will print when print this page from File > Print</h3></div>
<div class="noprint">This is another block which will not print...</div>
</div>
</body>
</html>

Just make a html page by above code and print it from File > Print

Comments (7)

Unknown
Really nice post... Thanks
Jitu
Very useful
Morshed Alam Author
Thanks for your comment.
Unknown
Thanks for your post. Would you please help to print a hidden block?
Morshed Alam Author
Thanks for your posting. Please take a look - http://morshed-alam.blogspot.com/2009/12/how-to-print-hidden-block-of-html-page.html <br /><br />Let me know if you need any other help. I will be pleased to help you.
Morshed Alam Author
<a href="http://morshed-alam.blogspot.com/2009/12/how-to-print-hidden-block-of-html-page.html" rel="nofollow ugc">How to print hidden block of an html page?</a>
Unknown
Thanks for your help

Leave a Comment