An HTML button is generally used to submit a form. However, you can create a button that works like a link. There are a couple of ways to make a button link. I mentioned them below.
<button onclick="window.location = 'https://shihabiiuc.com'">Learn more</button>
Here the “onclick” is one of many JavaScript events.
You can put any link between the single quotes. And by clicking the button, it will redirect you to the destination.
Relative link path
In the above example, it’s an absolute path. If you need to add a relative link path, use the following example below.
<button onclick="window.location = './about.html'">Learn more</button>
Here the “./” refers to the same directory as the file you’re editing. If you have the “about.html” in a folder called “pages” then the relative path will be this:
<button onclick="window.location = './pages/about.html'">Learn more</button>
<button onclick="window.open('https://shihabiiuc.com')">Leran more</button>
In the button link (using JavaScript), you can’t use the “target=_blank” attribute. To open a button link in a new tab, you have to use “window.open” instead of “window.location.”
The first example works without any problem. However, here is another way that you may already know.
You can wrap the button in an anchor tag <a> to make it act like a link. See the example below.
<a href="https://shihabiiuc.com"><button>Learn more</button></a>
Change mouse to cursor on hover
Now if you hover any of the buttons, the mouse cursor remains the same. You will definitely want the cursor to be a pointer just like a link behavior. Use one line of CSS to do that just.
button {
cursor: pointer;
}
Do you also need other CSS to style the button such as color, font, box-shadow, etc? Please let me know.
- What is the difference between a link & button?
- How to create an HTML button that works like a link?
- How to style buttons with CSS
- How to center a button in CSS?
- How to create an image button?
- Button border examples
- Rounded buttons
- How to create back to top button in HTML, CSS & JavaScript
- How to create a close button?
- How to remove the button border?
Learn more about HTML links
- How to add a link in HTML?
- How to open a link in a new tab in HTML?
- How to create an HTML download link?
- What is the difference between a link & button?
- How to create an HTML button that works like a link?
- How to make a div clickable link?
- How to create HTML anchor links that jump to another section?
- How to create an HTML mailto link (including email subject)?
- How to center a link in HTML & CSS?
- How to deactivate links using CSS?
- How to remove the underline from a link?
Conclusion
Now you know how to create an HTML button that works like a link. Also, I gave you multiple examples. If you still have any questions, please let me know.