← Back to Bootstrap Course | Chapter 10: Responsive Design | Lesson 6 of 7

Print utilities

Print utilities control what appears when a page is printed.

In this page:

  1. Print utilities
Syntax
markup
<nav class="d-print-none">hidden when printing</nav>
<div class="d-none d-print-block">only when printing</div>

Print utilities

Use .d-print-none to hide elements such as navigation when printing, .d-print-block or .d-print-inline to show print-only content and .d-none .d-print-block for print-only headers.

Combine with screen classes like d-none d-print-block. Test with the browser's print preview.

Note: Hide navbars, buttons and ads from printed pages with d-print-none.

Example: Print utilities

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="d-print-none alert alert-secondary">This banner is hidden when printing.</div>
  <div class="d-none d-print-block">This text is only visible on the printed page.</div>
  <p>This paragraph appears on screen and in print.</p>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting to hide navigation
  2. Printing with dark backgrounds
  3. Not testing print preview
Chapter Summary
  • d-print-none hides when printing
  • d-print-block shows only when printing
  • Combine with d-none
  • Check the print preview
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.