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: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–5Not supported
6+Supportedsince Aug 16, 2011
Current: 157Safari
1–12.1Not supported
13+Supportedsince Sep 19, 2019
Current: 27MobileChrome Android
18–62Not supported
63+Supportedsince Dec 5, 2017
Current: 155Firefox Android
4–5Not supported
6+Supportedsince Aug 16, 2011
Current: 157Safari iOS
1–12.2Not supported
13+Supportedsince Sep 19, 2019
Current: 27How 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
}Documentation (MDN)
Usage share
Sub-features
Support for each part of the feature (2). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Window.afterprint_event | 63 | 12 | 6 | 13 | 63 | 6 | 13 |
| Window.beforeprint_event | 63 | 12 | 6 | 13 | 63 | 6 | 13 |