HTML onafterprint Event Attribute Last Updated : 28 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The HTML onafterprint Event Attribute works when a page has started printing, or if the print dialogue box has been closed. This attribute is used together with the onbeforeprint attribute. This attribute is typically associated with the window or document element and is part of the WindowEventHandlers interface. Basically, it is fired after a document is successfully printed or previewed and is useful for executing actions specifically intended for post-printing scenarios.Syntax: <element onafterprint = "script">Supported Tags:<body>Attribute Value:This attribute contains a single value which works when an event attribute is called. This attribute is associated with <body> tag. Example 1: In this example, we will see the implementation of onafterprint Event Attribute. html <!DOCTYPE html> <html> <head> <title>title attribute</title> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body onafterprint="myFunction()"> <h1> GeeksforGeeks </h1> <h2> onafterprint attribute </h2> <!-- The script run when page will print --> <script> function myFunction() { alert("This document is now being printed") } </script> </body> </html> Output: Example 2: In this example, we will see the implementation of onafterprint Event Attribute. HTML <!DOCTYPE html> <html> <head> <title>title attribute</title> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body onafterprint="myFunction()"> <h1> GeeksforGeeks </h1> <h2> onafterprint attribute </h2> <!-- The script run when page will print --> <script> function myFunction() { console.log("This document is now being printed") } </script> </body> </html> Output: Supported Browsers: Google Chrome 1 and aboveEdge 12 and aboveFirefox 1 and aboveOpera 15 and aboveSafari 4 and above Create Quiz Comment V vijay_raj Follow 0 Improve V vijay_raj Follow 0 Improve Article Tags : Web Technologies HTML HTML-Tags HTML-Attributes Explore HTML BasicsHTML Introduction4 min readHTML Editors4 min readHTML Basics7 min readStructure & ElementsHTML Elements4 min readHTML Attributes7 min readHTML Headings3 min readHTML Paragraphs3 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists3 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks2 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables10 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms5 min readHTML5 Semantics5 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List15+ min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like