MailSlurp logo

blog

Tailwind print styles: custom media query setup and real-world pitfalls

Learn how to add print-specific Tailwind classes, build clean PDF-friendly layouts, and avoid common print rendering issues.

If you searched for tailwind print styles, tailwind print media query, or print:hidden, you likely need one thing: reliable print/PDF output without rewriting your whole UI.

This guide gives you a practical setup that works in production apps.

Quick answer

Add a print screen in tailwind.config.js, then use classes like print:hidden, print:text-black, and print:p-0 to override screen-first styles for printed output.

Why print styles matter

Print and PDF output are still critical for:

  • invoices and billing records
  • receipts and fulfillment slips
  • support exports and compliance evidence
  • handoff documents for operations teams

If you skip print-specific styling, output often contains clipped components, dark backgrounds, and unreadable spacing.

Add print support in Tailwind config

Use a custom screen alias:

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      screens: {
        print: { raw: "print" },
      },
    },
  },
};

Now print:* utilities will apply only in print media.

Example component pattern

export function InvoiceCard() {
  return (
    <section className="rounded-xl bg-slate-900 text-white p-6 print:bg-white print:text-black print:p-0 print:rounded-none">
      <header className="flex items-center justify-between print:block">
        <h2 className="text-xl font-semibold">Invoice #10482</h2>
        <button className="btn btn-primary print:hidden">Download PDF</button>
      </header>
      <div className="mt-4 border-t border-white/20 print:border-slate-300">{/* line items */}</div>
    </section>
  );
}

Key point: hide interactive UI in print and neutralize dark-theme styling.

Goal Utility pattern
Hide controls/nav print:hidden
Remove dark backgrounds print:bg-white print:text-black
Tighten page spacing print:p-0 print:m-0
Remove cards/shadows print:rounded-none print:shadow-none
Keep section grouping readable print:border print:border-slate-300

Common failures (and fixes)

1. Text disappears in PDF preview

Cause: dark theme + inherited white text assumptions.

Fix: enforce print color classes at container boundaries.

2. Buttons and nav clutter output

Cause: no print-specific visibility rules.

Fix: hide non-document controls with print:hidden.

3. Content breaks across pages awkwardly

Cause: no page-break strategy.

Fix: add print-specific wrappers and consider CSS break rules for large tables/sections.

Render test workflow (fast and reliable)

  1. Validate in browser print preview.
  2. Export PDF and compare with expected layout.
  3. Check edge cases: long names, long tables, empty states, and mobile widths.
  4. Re-run after each major UI theme or component-system update.

When print docs represent email events or receipts

Many teams print records triggered by async email events. In that setup:

Final take

Tailwind print styles are simple to configure, but quality comes from discipline: isolate print-only behavior, test realistic data, and treat print output as a product surface, not an afterthought.