Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to create printable webpage using CSS media queries ?

  • Last Updated : 26 Mar, 2021

The media query is used to hide/show an element when printing the web pages. Use @media print query and set the visibility property to that element that needs to hide/show at printing. In this article, we use media query and visibility property to print the web page.

Example 1: In this example, we will print the body element at printing time. To hide the body element, set the visibility property to hidden inside the print media query.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to create printable webpage
        using CSS media queries?
    </title>
  
    <style>
        body {
            text-align: center;
        }
  
        h1 {
            color: green;
        }
  
        @media print {
            .noprint {
                visibility: visible;
            }
        }
    </style>
</head>
  
<body class="noprint">
    <h1>GeeksforGeeks</h1>
  
    <p>
        GeeksforGeeks: It is a computer
        science portal for geeks
    </p>
  
</body>
  
</html>

Output:



Example 2: In this example, we will print the body element at printing time. To hide the body element, set the visibility property to hidden inside the print media query.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to create printable webpage
        using CSS media queries?
    </title>
  
    <style>
        body {
            text-align: center;
        }
  
        @media print {
            .noprint {
                visibility: visible;
            }
        }
    </style>
</head>
  
<body class="noprint">
    <img src=
         alt="GFG">
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :