How do I close a browser window with HTML code?

Use the below code example.

<input type="button" value="Close this window" onclick="self.close()">

Tip: When this button is clicked the browser will prompt the user if it is ok to close the window. This prompt cannot be bypassed. If your using a browser that supports tabs, the tab for this window does close without a prompt.


Tip: Before clicking the below button remember the shortcut key Ctrl + Shift + T, which will undo any closed tab. This allows you to get back to this page after its been closed in browsers that support tabs.

Additional information

  • See our close and window definitions for further information and related links on these term.