HTML DOM Window alert() Method Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The alert() method in HTML and JavaScript is used to display an alert box with a specified message. The alert box includes an OK button and is typically used to ensure that the user receives critical information or confirmation before proceeding.Note: Alert boxes grab your attention and make you read a message and Using too many alerts stops you from doing other things on the webpage until you close them.Syntaxalert(message);Parameter:Message: It is the message that is needed to show in the alert box and it's optional.Example: Display an alert box by double-clicking a button. In this example the alert() is used to display a message box when the button is double-clicked. The message informs users about GeeksforGeeks. It's a simple way to show notifications or information. html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <p> For displaying the alert message, double click the "Show Alert Message" button: </p> <button ondblclick="myalert()"> Show Alert Message </button> <script> function myalert() { alert("Welcome to GeeksforGeeks.\n " + "It is the best portal for computer" + "science enthusiasts!"); } </script> </body> </html> Output:Example: Alert the hostname of the current URLIn this example we displays the hostname of the current URL when the "Show Hostname" button is clicked. The showHostname() function retrieves the hostname using window.location.hostname and shows it in an alert box. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Alert Hostname Example</title> </head> <body style="text-align: center;"> <h1 style="color: green;"> Geeks </h1> <p> To see the hostname of the current URL, click the "Show Hostname" button: </p> <button onclick="showHostname()"> Show Hostname </button> <script> function showHostname() { let currentURL = window.location.hostname; alert("The hostname of the current URL is: " + currentURL); } </script> </body> </html> Output:Supported Browsers: Google ChromeEdge FirefoxOperaSafari HTML DOM Window alert() Method Comment S Shubrodeep Banerjee Follow Improve S Shubrodeep Banerjee Follow Improve Article Tags : Web Technologies HTML HTML-Methods Explore HTML BasicsHTML Introduction5 min readHTML Editors5 min readHTML Basics7 min readStructure & ElementsHTML Elements5 min readHTML Attributes8 min readHTML Headings4 min readHTML Paragraphs5 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists5 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks3 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 Semantics6 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