Skip to content

CSS for printing

The following properties are only active when your visitors print your web pages or export them as PDF via the browser.
They allow you to control display, page breaks, and formatting specific to the print media type.


PropertyDescription
marksAdds crop marks and alignment marks (professional printing).
orphansDefines the minimum number of lines of a paragraph to show at the bottom of a page before a break.
widowsDefines the minimum number of lines of a paragraph to show at the top of a page after a break.
page-break-beforeForces a page break before the element.
page-break-afterForces a page break after the element.
page-break-insideControls page breaks inside an element (auto, avoid).
pageDefines the page type or template to use.
sizeDefines the size and/or orientation of the page (A4, letter, landscape, etc.).

@media print {
/* Prevent splitting a table across pages */
table {
page-break-inside: avoid;
}
/* Force a page break before each heading */
h1 {
page-break-before: always;
}
/* Set page size to A4 in portrait orientation */
@page {
size: A4 portrait;
margin: 2cm;
}
}

  • PDF generation: Many web applications offer PDF export (invoices, tickets, reports).
    → These properties allow structuring the printed document properly.
  • Accessibility and reading comfort: Controlling orphans and widows (orphans, widows) prevents poorly split paragraphs and improves readability.
  • Professional documents: For reports, resumes, contracts, educational material… proper print rendering gives a more professional impression.
  • Compliance with standard formats: @page and size make it possible to produce content directly adapted to A4, Letter, etc., useful in an international context.
  • Compatibility with modern browsers: Chrome, Edge, Safari, and Firefox widely support these properties in their printing/PDF engines.

  • Always include a @media print stylesheet if your site generates printable content.
  • Use page-break-inside: avoid for tables, images, and important sections.
  • Define @page { size: A4; margin: ... } to produce clean PDF output.
  • The orphans and widows properties provide better typographic control.
  • These tools are essential for any site that offers PDF export or high-quality printing.