Favorites

DOM Window.alert() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.alert()
DOM Window MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The alert() method shows a simple message box and waits until the user dismisses it.

Description

The alert() method displays a modal message box with an OK button. It blocks the page, and all scripts, until the user closes it. Browsers style it themselves, may suppress it when it's shown repeatedly, and block it in sandboxed frames.

It's handy for quick debugging, but for real interfaces a <dialog> element or an on-page message gives a better experience. Use console.log() for debugging output.

The message is plain text, so HTML in it is shown literally, and line breaks can be added with \n. Because it pauses all scripts, timers and animations stop while it's open, which can make it misleading when debugging time-sensitive code.

Syntax

alert()
alert(message)

Parameters

  • messageOptional. The text to show.

Return Value

None (undefined).

Example

<button id="btn" type="button">Show alert</button>
document.getElementById('btn').addEventListener('click', () => {
  alert('Your changes have been saved.');
  console.log('alert closed');
});

Browser Support

The following information will show you the current browser support for the Window.alert() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee