HTML Button Link: How to Navigate to Another Page

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.

Flow showing navigation from a button-like link to another web page
Example of button-style navigation on a web page

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.

Rule of thumb: use <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.
HTML button with onClick event with location to link between web pages using address or URLs

Video tutorial on text links in Part I

Recommended: Style an Anchor as a Button Top ↑

If 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>

Visit plus2net

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.

Button Navigation with JavaScript Top ↑

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.

Legacy input-button form Top ↑

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">

Do Not Nest a Button Inside a Link Top ↑

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.

Open a Link in a New Tab Top ↑

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)

Avoid 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.

Go to plus2net home page

<a href="../">
  <img src="../images/top2.jpg" alt="Go to plus2net home page">
</a>

Confirm Before Navigation Top ↑

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>

Child Windows and 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.

Original child-window actions Top ↑

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>

CSS and Bootstrap Button Styles Top ↑

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

Using Bootstrap styles Top ↑

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

Accessibility and Usability Top ↑

  • Use links for navigation and buttons for actions so assistive technologies announce the correct control type.
  • Write descriptive link/button text. Avoid vague labels such as “click here” when a clearer destination or action is possible.
  • Do not remove the visible keyboard focus indicator unless you replace it with an equally clear focus style.
  • If a link opens a new tab, communicate that behavior in the link text or nearby accessible text.
  • For image links, write alt text that communicates the destination or purpose of the link.
  • Inside forms, specify type="button" for buttons that should not submit the form.

Common Button-Link Mistakes Top ↑

Using JavaScript for every link Top ↑

If the user is simply going to another URL, use an anchor with href. JavaScript adds unnecessary dependency for basic navigation.

Nesting interactive controls Top ↑

Do not put a button or <input type="button"> inside an anchor. Style the anchor itself.

Using 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.

Forgetting a button type inside a form Top ↑

A <button> associated with a form can submit it by default. Use type="button" when submission is not intended.

Opening new tabs unexpectedly Top ↑

Opening a new tab changes the user's browsing context. Use it intentionally and make the behavior clear.

Frequently Asked Questions Top ↑

Q1: How do I make a button link to another page in HTML?

For normal navigation, use an anchor with an href and style the anchor like a button. This preserves correct link semantics without requiring JavaScript.

Q2: Can I use onclick to open a URL from a button?

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.

Q3: Can I put a button inside an anchor tag?

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.

Q4: How do I open a button-like link in a new tab?

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.

Q5: Should I use a link or button for navigation?

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.

Q6: Why should a non-submit button inside a form have type="button"?

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.


HTML
Hyper-linking Submitting a form using Image as button
HTML Form



plus2net.com







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.



We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer