An alert box is simply a dialog box that can be used in websites. It's a fun way to interact with the visitors on your website. In this article, you'll discover how to use JavaScript to create a basic alert box.

Steps

  1. 1
    Open up the text editor that you use. On windows, notepad++ is recommended. Many free, open-source text editors exist such as Atom, and visual studio code.
  2. 2
    Add your HTML. Before you can add JavaScript, you need the content of your webpage. In this example, we create a simple HTML document with head, title and body tags.
    <!DOCTYPE html>
    <html>
    	<head>
    		<title>Page Name</title>
    	</head>
    	<body>	
    	</body>
    </html>
    
  3. 3
    Inside the <body> tags, create a <script> tag and set the <type> to "text/javascript". The <script> tags allow us to directly insert JavaScript code into our HTML.
  4. 4
    Between the <script> tags we will write our code. The JavaScript function alert will create a simple message box which contains text specified in the first argument:
    alert("Your message here!");
    
  5. 5
    Open up the HTML document that you just created using any browser. You'll see the alert message pop up.

About This Article

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 10 people, some anonymous, worked to edit and improve it over time. This article has been viewed 9,550 times.
How helpful is this?
Co-authors: 10
Updated: July 3, 2020
Views: 9,550
Categories: JavaScript