Open In App

Bootstrap 5 Display in Print

Bootstrap 5 Display in print is used to display or hide some content when printing. This can be combined with viewports also. For example, some content can be made to show to all viewports except large screens and it is also made invisible when we print that page. 

Bootstrap 5 Display in print Classes:



Syntax:

<div class="d-print-*">...</div>

Note: This * can be substituted with various print display utility classes



Example 1: In this example, we will learn about Display in Print




<!DOCTYPE html>
<html>
  
<head>
    <link href=
        rel="stylesheet" integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" 
        crossorigin="anonymous">
</head>
  
<body>
    <div class="container text-center">
        <h1 class="text-success">
            GeeksforGeeks
        </h1>
        <h2>
            Bootstrap 5 Display in print
        </h2>
        <div class="d-print-none">
            <p class="text-danger">
                I won't be visible when u will print this webpage
            </p>
            <img src=
                height="200px" width="200px">
        </div>
        <div class="d-none d-print-block">
            <p class="text-danger">
                I will be visible only when u will print this webpage
            </p>
            <img src=
    height="200px" width="200px">
        </div>
    </div>
</body>
</html>

Output:

Bootstrap 5 Display in Print

Example 2: In this example, we will learn about Display in Print along with display utility classes. We will see the usage of d-xl-block along d-print-none class.




<!DOCTYPE html>
<html>
  
<head>
   <link href=
        rel="stylesheet" integrity=
"sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" 
        crossorigin="anonymous">
</head>
  
<body>
    <div class="container text-center">
        <h1 class="text-success">
            GeeksforGeeks
        </h1>
        <h2>
            Bootstrap 5 Display in print
        </h2>
        <div class="d-none d-xl-block 
            d-print-none">
            <p class="text-danger">
                I won't be visible on smaller screens and 
                when u will print this webpage
            </p>
            <img src=
                height="200px" width="200px">
        </div>
        <div class="d-none d-print-block">
            <p class="text-danger">
                I will be visible only when u will print this webpage
            </p>
            <img src=
                height="200px" width="200px">
        </div>
    </div>
</body>
</html>

Output:

Bootstrap 5 Display in Print

Reference: https://getbootstrap.com/docs/5.0/utilities/display/#display-in-print


Article Tags :