How to Create a Website Back Button

JavaScript back button code for an HTML Page

Red back button

Ironbrother / Public Domain

Anytime you browse a website, hitting the browser's back button will let you return to the previous page. Website designers can also create a back button that resides right on the page, making it easier to navigate through the site's content. Here's a look at creating a website back button using JavaScript code.

Website back buttons rely on the user's browsing history, so they won't work if a user opens a page in a new browser tab.

Basic Back Button Code

The basic code for a back button link is very simple:

 <input type="button" value="Go back" onclick="history.back()">

Copy and paste this back button code wherever you want the "Go Back" link to be found on your page. If you prefer, change the text for it to read as something else, such as, "Go back to the previous page."