For normal page navigation, use an HTML <a href> link and style it like a button. A real <button> is intended for actions such as submitting a form, opening a dialog or running JavaScript.
<a href="../" class="btn btn-primary">Visit Home Page</a>
This gives users normal link behavior such as opening the destination in a new tab from the browser context menu, while still allowing the link to look like a button.

Older pages often use an onclick handler on an input or button to change location.href. That still works, but JavaScript is not needed when the user's intent is simply to follow a URL.
<a href> for navigation and <button> for actions. If a button genuinely performs an action and then navigation is part of that action, JavaScript can be appropriate.Video tutorial on text links in Part I
Show Table of ContentsIf clicking the control should take the user to another URL, an anchor is the semantic HTML element for the job. You can style it with your own CSS or with Bootstrap classes.
<a href="https://www.plus2net.com/" class="btn btn-primary">Visit plus2net</a>
This keeps a real URL in the href attribute, which is better for link semantics, keyboard/browser behavior and crawlable navigation than requiring JavaScript for a simple page change.
If you specifically need a button because clicking it performs application logic, JavaScript can change the current page with window.location.href.
<button type="button" onclick="window.location.href='../'">Visit Home Page</button>
Older examples may use parent.location. That targets the parent browsing context and is mainly relevant when a page is inside a frame. For ordinary top-level navigation, window.location.href or simply an anchor link is clearer.
An <input type="button"> can also run JavaScript, but <button type="button"> is generally easier to read and can contain richer content.
<input type="button" onclick="window.location.href='../'" value="Visit Home Page">
The legacy pattern below should not be used:
<!-- Avoid: nested interactive controls -->
<a href="../"><input type="button" value="HOME"></a>
An anchor that has an href is already interactive content. Do not place another interactive control such as <input type="button"> or <button> inside it. Style the anchor itself instead.
The older article on search engine friendly page design remains available for related background.
Use target="_blank" when there is a genuine reason to open another browsing context. Tell users when a link opens a new tab because unexpected context changes can be confusing.
<a href="https://www.plus2net.com/" target="_blank" rel="noopener">
Visit plus2net (opens in a new tab)
</a>
Visit plus2net (opens in a new tab)
target="new" in new examples. A named target such as new can reuse the same browsing context. Use the standard _blank keyword when you intentionally want a new tab/window.An image can be placed inside an anchor when the image itself is the link. Give the image useful alternative text that describes the link's purpose.
<a href="../">
<img src="../images/top2.jpg" alt="Go to plus2net home page">
</a>
If navigation depends on a user decision, JavaScript can confirm the action first. A normal link is still preferable when no confirmation or other application logic is required.
<button type="button" onclick="confirmRedirect()">Go to plus2net.com</button>
<script>
function confirmRedirect() {
if (confirm("Do you want to visit the page?")) {
window.location.href = "https://www.plus2net.com/";
}
}
</script>
window.open() Top ↑The original tutorial includes a useful demonstration of opening a child window and communicating with its opener. This is a specialized JavaScript use case, not the recommended method for ordinary hyperlinks.
Read more on child window control in the JavaScript section.
<button type="button" onclick="window.open('button-child.php','demo','width=550,height=300,left=150,top=200,toolbar=0,status=0')">
Open child Window
</button>
The preserved child-window demo uses window.opener to control the page that opened it. Modern browser security rules restrict opener access across origins, and popup blocking can prevent windows that are not opened directly from a user action.
The following patterns illustrate the original same-origin opener concept:
<button type="button" onclick="opener.location='https://www.plus2net.com/'">Change the opener page</button>
<button type="button" onclick="location='https://www.plus2net.com/'">Change this window</button>
<button type="button" onclick="self.close()">Close this window</button>
Button-like links and real buttons can both be styled with CSS. Keep their semantics based on what they do, then apply the visual style separately.
DEMO of Buttons with CSS properties
Bootstrap button classes can style either anchors or buttons. These are real buttons because the controls below are demonstrations rather than navigation links.
Read more about Bootstrap buttons in the jQuery section
alt text that communicates the destination or purpose of the link.type="button" for buttons that should not submit the form.If the user is simply going to another URL, use an anchor with href. JavaScript adds unnecessary dependency for basic navigation.
Do not put a button or <input type="button"> inside an anchor. Style the anchor itself.
target="new" as if it means a new tab every time Top ↑new is only a browsing-context name. Use target="_blank" for the standard new-context behavior.
A <button> associated with a form can submit it by default. Use type="button" when submission is not intended.
Opening a new tab changes the user's browsing context. Use it intentionally and make the behavior clear.
For normal navigation, use an anchor with an href and style the anchor like a button. This preserves correct link semantics without requiring JavaScript.
Yes. A button can set window.location.href, but this is most appropriate when the control performs an action or other JavaScript logic. A simple URL should normally use an anchor.
No. A link with an href and a button are both interactive controls, so they should not be nested. Style the anchor itself to look like a button.
Use an anchor with target="_blank". Adding rel="noopener" makes the intended opener isolation explicit, and users should be told that a new tab will open.
Use a link when the result is navigation to a URL. Use a button when the control performs an action such as submitting data, toggling a UI component or running application logic.
Buttons associated with a form may submit it by default. Setting type="button" prevents accidental submission when the button is intended only to run another action.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| rozel rosauro | 22-03-2012 |
| it is very helpful to me ...thanks | |
| N G Sundar | 14-05-2012 |
| Exactly what I wanted. Did not want to submit the form; instead wanted to go to another page. | |
| rozel rosauro | 05-06-2012 |
| it is very helpful to me ...thanks | |
| chavda bhavna | 07-08-2012 |
| nice understanding exampels.good.thanks. | |
| DekeR | 19-09-2012 |
| very helpfull - just ask google, and dont need read API or something like that, THX | |
| harini | 26-12-2012 |
| Amazing article.. thanks for the help. | |
| sanju | 07-01-2013 |
| how i can open a folder from pc by clicking button and change photo by selecting any photo | |
| venkat | 15-03-2013 |
| very useful .... | |
| Vengefull | 16-07-2013 |
| Good article, very helpfull. Thank you. | |
| anis | 19-04-2014 |
| what is the different between location and parent.location | |
| lyn | 27-05-2014 |
| Its really helpful :,) tq so much | |
| wiki | 10-07-2014 |
| Thanks you sooo much,,, this is what i'm looking for... | |
| makbul | 28-09-2014 |
| i want to generate click evant on a .cs with use of html button | |
| JohnC | 09-10-2014 |
| Thank you all. This has enabled me to get our local site running. Do you have a book available for purchase or download? Once more thank you so very much. | |
| rasool | 30-04-2015 |
| Tnx A Lotttttt ! Best Site Ever :) | |
| Ken | 09-06-2015 |
| Thank you so much!!! | |
| Ishman | 08-10-2015 |
| How do i pass parameter while redirecting to other page using onClick function | |
| KyleInMC | 16-10-2015 |
| Um... the open.window onClick thing doesn't work in the Google Sites editor. It says "Missing or malformed url parameter" what do I do? | |
| Bramhananda reddy | 28-02-2016 |
| Apart from other stuff Your Explanation in practical is really very nice.Keep it up and wish u all the best | |
| Hasini Silva | 03-07-2016 |
| This is amazing. Thanks a lot! | |
| manik | 03-11-2017 |
| thanks for this i had been looking for this from a long time and found it here | |
| ibexy | 20-05-2018 |
| can this be used with image links? | |
| smo1234 | 10-08-2018 |
| To take the parameter to different page or different site , you can use query string. | |
| smo1234 | 10-08-2018 |
| One image ( plus2net logo ) is added as a link to home page. | |