How to Edit a JavaScript Alert Box Title ? Last Updated : 04 Apr, 2024 Comments Improve Suggest changes Like Article Like Report We can't directly modify the title of the alert box because the title is controlled by the browser and cannot be changed by JavaScript. However, we can create a custom alert box. Table of Content Using a Custom Alert Box FunctionUsing SweetAlert LibraryUsing a Custom Alert Box FunctionIn this approach, we are creating a function that dynamically generates an alert box with a customizable title and message. This approach allows us to have more control over the appearance and behavior of the alert box compared to the standard alert() function in JavaScript. Example: The below example creates custom function to edit a JavaScript alert box title. HTML <!DOCTYPE html> <html> <head> <title>Custom Alert Box</title> <style> .container{ text-align: center; } h1{ color: green; } .custom-alert { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; border: 1px solid #ccc; padding: 20px; border-radius: 5px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); } </style> </head> <body> <div class="container"> <h1>GeeksForGeeks</h1> <h3>Using custom function</h3> <button onclick= "showAlert('Custom Alert', 'This is a custom alert box.')"> Show Alert </button> </div> <script> function showAlert(title, message) { // Create a custom alert box const alertBox = document.createElement('div'); alertBox.className = 'custom-alert'; alertBox.innerHTML = ` <h2>${title}</h2> <p>${message}</p> <button onclick="document.body.removeChild(this.parentElement)">OK</button> `; document.body.appendChild(alertBox); } </script> </body> </html> Output: Using SweetAlert LibraryIn this approach we are using SweetAlert library which allows us to create custom-styled alert boxes with ease. It provides a simple and elegant way to display alerts, prompts with customizable titles, messages, and buttons. Example: The below example uses SweetAlert Library to add custom title in alert box. HTML <!DOCTYPE html> <html> <head> <title>Custom Alert Box</title> <script src= "https://cdn.jsdelivr.net/npm/sweetalert2@11"> </script> </head> <style> .container { text-align: center; } h1 { color: green; } </style> <body> <div class="container"> <h1>GeeksForGeeks</h1> <h3>Using SweetAlert library</h3> <button onclick="showCustomAlert()"> Show Alert </button> </div> <script> function showCustomAlert() { // Create a custom alert box with SweetAlert Swal.fire({ title: 'This is a Custom Alert title', text: 'Welcome to geeksForGeeks', confirmButtonText: 'OK' }); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Edit a JavaScript Alert Box Title ? Y yuvraj07 Follow Improve Article Tags : Web Technologies JavaScript Similar Reads How to edit a JavaScript Alert Box Title in Bootstrap ? JavaScript alert boxes are an essential component, frequently used to deliver important messages or notifications to users. There are two methods to edit the title of a JavaScript alert box. First, you can create a custom modal dialog, offering complete control over appearance and functionality. Alt 3 min read How to Center the JavaScript Alert Message Box ? To center the JavaScript alert message box, you can use CSS to define a custom alert box with fixed positioning and the transform property to adjust its position in the center of the viewport. ApproachFirst, create the layout of the web page using elements. styles alert box using CSS, positioning it 2 min read How to Center the JavaScript Alert Message Box ? An alert box is a dialogue box that pops up on the screen to provide information to the user. It contains a message and an OK button, which allow users to acknowledge the message and close the box. Alert boxes are commonly used in web development to display important messages, warnings, or notificat 4 min read How to Design a Custom Alert Box using JavaScript ? An alert box is a built-in feature in JavaScript that displays a small window with a message to the user. It's primarily used for providing information to the user, displaying warnings, or prompting the user for confirmation. The below approaches can be used to create a custom alert box in JavaScrip 4 min read How to Create an Alert in JavaScript ? The alert() method in JavaScript displays an alert box with a message and an OK button. It's used when you want information to come through to the user, providing immediate notifications or prompts for user interaction during program execution. Note: Alert boxes interrupt user interaction, shifting 1 min read Like