coderef

Print eventsBaseline · Widely available

An alternative to @media print queries, the beforeprint and afterprint events allow you to change the page for printing and restore the page after printing.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Sep 19, 2019. Widely available since Mar 19, 2022.

Browser support

DesktopChrome
1–62Not supported
63+Supportedsince Dec 6, 2017
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–5Not supported
6+Supportedsince Aug 16, 2011
Current: 157
Safari
1–12.1Not supported
13+Supportedsince Sep 19, 2019
Current: 27
MobileChrome Android
18–62Not supported
63+Supportedsince Dec 5, 2017
Current: 155
Firefox Android
4–5Not supported
6+Supportedsince Aug 16, 2011
Current: 157
Safari iOS
1–12.2Not supported
13+Supportedsince Sep 19, 2019
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: afterprint event.

Feature detection

JS · check before using
if ("onafterprint" in Window.prototype) {
  // the afterprint event is supported
}

Sub-features

Support for each part of the feature (2). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Window.afterprint_event631261363613
Window.beforeprint_event631261363613