Tailwind CSS Print Styles: Print-Optimized Layouts with Tailwind
AI generated
</>
tw
Tailwind CSS · Print Styles · Print Layout · PDF
Tailwind CSS Print Styles:
print-optimized layouts without a separate stylesheet

Professional print layouts without maintaining a separate print stylesheet: the print variant of Tailwind CSS enables fully print-specific utility classes directly in the template. Hide navigation elements, adjust colors for print, control page breaks and output URLs in the print layout, all with Tailwind CSS Print Styles.

11 min read print variant · @page · break-before · break-after · URLs Tailwind CSS v3 · v4 · invoices · reports

1. Why print styles still matter

The web has not replaced print. Invoices, delivery notes, reports, certificates and documentation are still printed, and the first impression an application makes on paper is often catastrophic because print styles were forgotten. A page without Tailwind CSS Print Styles prints the navigation, sidebar, footer, cookie banner and every background color, wasting paper and ink and leaving an unprofessional impression. Yet implementing print styles with Tailwind CSS is considerably simpler than hand-writing a separate print stylesheet.

The most common mistake: developers only think about print styles once a customer prints an invoice and complains. By then the damage is already done. The better practice is to consider print styles from the start as part of component design, defining for every component how it should look on paper. With the Tailwind CSS Print Styles variant print: that is possible directly in the template, without maintaining a separate stylesheet.

Another frequently overlooked use case is browser-based PDF generation. Many applications use window.print() or a headless browser like Puppeteer to produce PDFs. The Tailwind CSS Print Styles apply in both scenarios, direct printing and PDF generation via @media print. A well-maintained print layout can save you from reaching for a separate PDF library for many common document types.

Since Tailwind CSS v3 there is a built-in print: variant. It works exactly like the responsive variants (sm:, lg:) or state variants (hover:, focus:): as a prefix in front of the utility class. The class print:hidden corresponds to the CSS @media print { .print\:hidden { display: none; } }. Every Tailwind utility can be combined with the print: variant, covering layout, typography, colors, spacing and more. That makes Tailwind CSS Print Styles a complete solution for print-specific layouts.

The print: variant does not need to be enabled separately in the content configuration; like every variant, it is automatically active as soon as a class with this prefix is found in the template files. So writing print:hidden in an HTML template automatically produces the corresponding CSS rule in the output. That is the core idea behind JIT-based Tailwind CSS Print Styles: only print utilities that are actually used end up in the bundle.


/* Example: print-specific classes in a Tailwind HTML template */

/* Navigation, hidden when printing */
/* <nav class="print:hidden flex items-center justify-between p-4 bg-slate-900"> */

/* Print-only elements, hidden on screen, visible when printing */
/* <div class="hidden print:block text-xs text-gray-500"> */
/*   Printed on: 2026-05-09, mironsoft.de */
/* </div> */

/* Adjust text color for print, ensure black text on white paper */
/* <p class="text-gray-600 print:text-black text-sm leading-relaxed"> */

/* Adjust layout for print, full width, no grid gaps */
/* <div class="grid grid-cols-3 gap-8 print:grid-cols-1 print:gap-0"> */

/* Remove shadows and borders that look bad when printed */
/* <div class="shadow-xl rounded-2xl print:shadow-none print:rounded-none"> */

/* Keep a heading with its following paragraph, avoid orphan headings */
/* <h2 class="print:break-after-avoid text-xl font-bold mt-8">Section</h2> */

3. Showing and hiding elements for print

The most basic Tailwind CSS Print Styles task is hiding elements that make no sense in a printout: navigation, sidebar, footer, CTA buttons, cookie banners, social media links, interactive elements and ads. With print:hidden these elements are hidden from the printer while remaining visible on screen. The counterpart is hidden print:block for elements that should only appear in print, for example a printed address, a barcode, or a note pointing to the digital version with its URL.

A common mistake: developers forget that print:hidden hides the element, but the space in the layout can still be occupied if flex or grid containers are not adjusted accordingly. A print:hidden on a flex child element visually removes the element, but the container redistributes the space. In some cases the container itself also needs print: variants. The best strategy is therefore to think of the entire print layout separately, not merely hiding individual elements but actively designing the layout for print.

4. Adjusting colors and backgrounds for print

Browsers do not print background colors and images by default, in order to save ink, unless the user enables "print background graphics" in the print settings. That means colorful Tailwind backgrounds like bg-sky-900 or bg-gradient-to-r appear as blank white areas in print, and white text sitting on top of them becomes invisible. For Tailwind CSS Print Styles that means every element with a background color needs a print-specific alternative: either force a background with print:bg-white and print:text-black, or use a bordered variant instead of a filled one.

The CSS property -webkit-print-color-adjust: exact (or the standardized print-color-adjust: exact) forces background colors to be output even without the user setting. In Tailwind v3 this property is set via the @tailwindcss/typography plugin or manually; in v4 there is the utility print-color-adjust-exact. Anyone who absolutely needs a colored logo or colored status badges in print for invoices or certificates must set this property, otherwise the Tailwind CSS Print Styles look different on paper than they do in the browser preview.


<!-- Print-optimized invoice header with Tailwind Print Styles -->
<div class="flex justify-between items-start p-8 bg-slate-900 text-white
            print:bg-white print:text-black print:border-b-2 print:border-slate-900 print:p-0 print:pb-6">

  <!-- Logo: visible on screen with white text, inverted for print -->
  <div class="text-2xl font-bold print:text-slate-900">Mironsoft GmbH</div>

  <!-- Invoice status badge: color forced for print output -->
  <span class="bg-green-500 text-white px-3 py-1 rounded-full text-sm font-bold
               print:bg-green-500 print:text-white [print-color-adjust:exact]">
    Paid
  </span>
</div>

<!-- Navigation bar, completely hidden when printing -->
<nav class="print:hidden sticky top-0 z-50 bg-white shadow-sm">
  <!-- navigation items -->
</nav>

<!-- Print-only footer with URL and date -->
<div class="hidden print:flex print:justify-between print:text-xs print:text-gray-500 print:mt-8 print:pt-4 print:border-t">
  <span>mironsoft.de</span>
  <span>Page <span class="print-page-number"></span></span>
</div>

5. Controlling page breaks with break-before and break-after

Page breaks are one of the trickiest challenges in Tailwind CSS Print Styles. Without explicit control, the browser decides where a page breaks, often in the middle of a table, a section, or even in the middle of a paragraph. Since v3 Tailwind offers the utilities break-before-page, break-after-page, break-inside-avoid, break-before-avoid and break-after-avoid. With the print: variant these can be enabled specifically for the print case: print:break-before-page forces a page break before the element, print:break-inside-avoid prevents a break inside the element.

A common use case for Tailwind CSS Print Styles breaks: multi-page reports with one section per page. Every section gets print:break-before-page, and the first section gets print:break-before-auto. Tables with long content get print:break-inside-avoid on the table rows, so rows are not split across two pages. Headings get print:break-after-avoid, so they never end up alone at the bottom of a page (the so-called widowed heading problem).

6. @page rules: page size, margins and running headers

The CSS @page rule is the counterpart to Tailwind CSS Print Styles at the page meta level: it controls the page size, margins and headers/footers of the printed document. Tailwind has no direct support for @page, because it is not a standard property-based system. You write @page rules as custom CSS in the @layer base directive or directly in the stylesheet, without using Tailwind utilities.

The most important @page settings for professional Tailwind CSS Print Styles: @page { size: A4; margin: 15mm 20mm; } defines A4 format with sensible margins. With @page :first the first page can have different margins, useful for cover pages. With @page :left and @page :right, even and odd pages can be styled differently for book printing. counter-reset: page and counter-increment: page enable page numbering in CSS without using JavaScript.


/* Custom CSS for @page rules, add to @layer base in Tailwind */
@layer base {
  /* Standard A4 page setup for invoices and reports */
  @page {
    size: A4;
    margin: 15mm 20mm 20mm 20mm;
  }

  /* First page, cover page with reduced margins */
  @page :first {
    margin-top: 30mm;
  }

  /* Running page counter in CSS (requires browser support) */
  @page {
    @bottom-right {
      content: "Page " counter(page) " of " counter(pages);
      font-size: 10pt;
      color: #64748b;
    }
  }

  /* Force black text and white background globally for print */
  @media print {
    * {
      -webkit-print-color-adjust: exact;
      print-color-adjust: exact;
    }
    body {
      font-size: 11pt;
      line-height: 1.5;
      color: #000;
      background: #fff;
    }
  }
}

7. Outputting URLs and QR codes in the print layout

A typical problem with print layouts: links are not clickable on paper. A hyperlink like "Learn more" is worthless to a reader without the URL. With plain CSS you can output the URL of a link in the print layout: content: " (" attr(href) ")" after the link element. Combined with Tailwind CSS Print Styles that means: a CSS rule inside @media print appends the URL after every <a> element that does not have a special suppression class.

For dynamic documents rendered as PDF by headless browsers, an HTML-based QR code via a library such as qrcodejs is also a good idea. The QR code can be embedded as a hidden print:block element, invisible on screen, visible in print. That gives the reader of the printed document a way to navigate straight to the digital version. This Tailwind CSS Print Styles technique is especially valuable for quotes, invoices and certificates where the digital signature or current status should be verifiable online.

8. Complete example: a print-optimized invoice

The full interplay of Tailwind CSS Print Styles techniques shows best with an invoice example. An invoice needs: a company logo and address in the header, invoice details in a structured table, a total with tax breakdown, payment information in the footer, page numbering and ideally the URL to the digital version. All of these elements can be styled correctly for print using Tailwind and the print: variant, without a single separate stylesheet.

Critical points when implementing an invoice with Tailwind CSS Print Styles: the line item table gets print:break-inside-avoid on every row, so line items are not split across page boundaries. The tax summary gets print:break-before-avoid, so it never starts alone on a new page while the previous page still has room. The entire payment details block gets print:break-inside-avoid as a unit. That prevents the account number and BIC from ending up on different pages.

9. Tailwind print styles vs. a separate print stylesheet

The traditional approach to print layouts is a separate stylesheet included via <link rel="stylesheet" media="print" href="print.css">. Compared to Tailwind CSS Print Styles, this approach has clear disadvantages: the print stylesheet has to be maintained separately and kept in sync when the main styles are refactored. If a component in the main file is restructured, the print stylesheet has to be adjusted manually, a common source of inconsistencies.

Aspect Separate print CSS Tailwind print styles Verdict
Maintainability Two files to keep in sync Everything in the template, co-located Tailwind wins clearly
@page rules Full support Only as custom CSS in @layer Separate CSS wins
Bundle size Extra HTTP request Part of the main CSS bundle Tailwind wins
Readability Clear separation of concerns Many print: classes in the HTML Matter of taste
Refactoring safety Drift after restructuring Always in sync with the screen layout Tailwind wins clearly

For most projects, the Tailwind CSS Print Styles approach is the better choice: print styles are defined directly on the element, always in sync with the screen layout, and no additional HTTP request is needed. For complex multi-page document layouts with demanding @page requirements, a combination of Tailwind print styles and a minimal supplementary stylesheet can be the optimal solution.

Mironsoft

Print layouts, PDF generation and Tailwind CSS Print Styles

Need print-optimized invoices and reports?

We implement professional print layouts with Tailwind CSS Print Styles, for invoices, delivery notes, reports and PDF generation via headless browsers. Page breaks, color management and @page configuration included.

Print audit

Analyze existing print layouts and introduce Tailwind Print Styles

Document layout

Invoices, quotes and reports made print-optimized and PDF-ready

Puppeteer PDF

Integrate headless browser PDF generation with Tailwind Print Styles

10. Summary

The Tailwind CSS Print Styles variant print: is the tool of choice for print-specific layouts in Tailwind projects. It lets you define print styles directly on the element, without a separate stylesheet, always in sync with the screen layout. The key patterns: print:hidden for navigation elements and interactive areas, hidden print:block for print-specific content, print:text-black print:bg-white for color corrections, and print:break-before-page and print:break-inside-avoid for page break control.

@page rules for page size and margins are the one area where Tailwind offers no direct support, custom CSS in @layer base helps as a supplementary solution here. For professional document layouts such as invoices and reports, the combination of Tailwind print styles and minimally necessary @page CSS is the most pragmatic and maintainable solution. Implementing it typically costs significantly less time than setting up a separate PDF library, and delivers a print result that is consistent across browsers.

Tailwind CSS Print Styles: the essentials at a glance

Print variant

print:hidden and hidden print:block, show and hide elements specifically for print. No separate configuration needed.

Page breaks

print:break-before-page, print:break-inside-avoid, print:break-after-avoid, control breaks precisely and avoid widowed headings.

Colors in print

print:text-black print:bg-white for safe color values. print-color-adjust: exact forces background colors even without a user setting.

@page

@page { size: A4; margin: 15mm 20mm; } as custom CSS in @layer base, Tailwind utilities do not apply to @page rules.

11. FAQ: Tailwind CSS Print Styles

1How do I enable the print variant?
Not necessary, it has been active by default since v3. Simply write print:hidden, print:block, and so on in templates; JIT generates the @media print rules automatically.
2print:hidden vs. display:none?
print:hidden only hides on print, visible on screen. display:none hides everywhere. Combine with hidden print:block for elements that should only be visible in print.
3Background colors in print?
Suppressed by default. Force them with print-color-adjust: exact. For critical colored elements in print, set this property directly on the element.
4Page breaks with Tailwind?
print:break-before-page, print:break-after-page, print:break-inside-avoid, so tables, sections and headings flow correctly across pages.
5@page rules with Tailwind?
Not directly, add @page as custom CSS in @layer base. Tailwind utilities do not apply to @page rules.
6Show URLs of links in print?
Custom CSS in @layer base: @media print { a[href]::after { content: ' (' attr(href) ')'; } }, shows the URL right after every link when printing.
7Puppeteer and print styles?
Yes. Set printBackground: true and mediaType: 'print' in the Puppeteer options. Then all Tailwind print styles apply during PDF generation.
8When to use a separate print stylesheet?
For complex @page requirements (book printing, running headers) or when the team prefers a separation of concerns. For most projects, Tailwind print styles are fully sufficient.
9Prevent a heading standing alone at the bottom of a page?
print:break-after-avoid on the heading, prevents a page break directly after the heading. The heading always stays with the content that follows on the same page.
10Different font sizes for print?
Yes, with print:text-sm and similar utilities. For a precise print font size, set font-size: 11pt in the @page custom CSS, pt is the correct unit for print layouts.