How do I close a browser window with HTML code?

Issue

How do I close a browser window with HTML code?

Solution

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.

Example

  • Category
  • HTML Q&A
  • Solved?
  • Were you able to locate the answer to your question?