Skip to content
Related Articles

Related Articles

Improve Article

HTML | onbeforeprint Event Attribute

  • Difficulty Level : Basic
  • Last Updated : 30 Jul, 2021

The onbeforeprint attribute works when a page is about to be printed. The alert message display before the print dialogue box appears. The onbeforeprint attribute is used with the onafterprint attribute.
Supported Tags 

  • <body>


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

<element onbeforeprint = "script">

Attribute Value: This attribute contains single attribute value script and it works when document is about to print. This attribute is supported by <body> tag.


<!DOCTYPE html>
        <title>onbeforeprint attribute</title>
            body {
            h1 {
    <body onbeforeprint="myFunction()">
        <h2>onbeforeprint attribute</h2>
        <!-- The script run when page will ready to print -->
            function myFunction() {
                alert("This document is ready to be printed");


Supported Browsers: The browser supported by onbeforeprint attribute are listed below: 

  • Chrome 63.0 and above
  • Internet Explorer
  • Firefox
  • Safari: Not supported
  • Opera: Not supported


My Personal Notes arrow_drop_up
Recommended Articles
Page :