Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWeb Page and Site Features

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Keep Specific Web Page Items From Printing

People print web pages from their browsers from time to time. The printing may be to paper or as a PDF.

If there is something on your web page that you do not want printed, a bit of CSS can allow the item to be seen in the browser but prevented from being printed.

Examples of items a person might not want printed with the rest of their web page are sale prices, ads, and other items that are seasonal or frequently updated. If you use a "tap to print" button, you may want the button itself absent from the printed page.

(See Include Special Message When Web Page Is Printed for the reverse effect, printing something that is not published on a web page.)

To keep certain items from being printed, this CSS does the trick.

@media print { .non-printable { display: none; } }

To tell the browser to hold back something when the web page is printed, assign class="non-printable" to the item.

As a demonstration, the next paragraph has class="non-printable" assigned to it.

If you print the web page, this paragraph should not print — whether you send it to your printer or print to a PDF. However, if this paragraph is in an email reader, even in a web page for reading email, the CSS to prevent printing might not be functional or have been stripped out by the email provider.

The class name may be something other than non-printable, if you wish — "noprint" or "printless" are examples. Specify the different class name in the CSS declaration and use it with the items you want to make non-printable.

Example Implementation of the Do-Not-Print-Me Feature

Here is the source code of a simple web page with three paragraphs. The middle paragraph does not print when a browser's "print" function is used to send the web page to the printer or to a PDF that may be printed later.

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Print/Non-print Test</title>

<style>
@media print { .non-printable { display: none; } }
</style>

</head>
<body>
<p>
The first paragraph on the page.
</p>

<p class="non-printable">
The second paragraph on the page (is not printable).
</p>

<p>
The third paragraph on the page.
</p>
</body>
</html>

When you get right down to it, it can be a simple implementation:

  1. Put the CSS declaration into the style tag.

  2. Use the class name to specify non-printable items.

Give it a test. You'll find it easy to implement.

(This article first appeared with an issue of the Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC