How to create an HTML button that acts like a link? There are multiple methods of making an HTML button, that behaves like a connection (i.e., tapping on it the client is diverted to the predetermined URL). You can pick one of the accompanying strategies to add a connection to the HTML button.
Once in a while, you might need to utilize a button to connect to another page or site rather than to present a structure or something to that effect. This is genuinely easy to do and can be accomplished in more ways than one.
Once in a while, we want to make an HTML button, that behaves like a connection (i.e., tapping on it the client is diverted to the predefined URL).
There are a few techniques, we will introduce 3 of them. Pick one of the accompanying techniques to add a connection to an HTML button. There are a few strategies to make an HTML button that goes about as a connection. Some of them are talked about underneath:
Note: Adding fundamental CSS property to the button in each strategy to make the button looks better.
1. Add inline onclick event
a) To HTML <button> tag within HTML <form> element.
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <button onclick="window.location.href = 'https://w3docs.com';">Click Here</button> </body> </html>
Try it yourself
It might not work if the button is inside a <form> tag.
b) To <input> tag within HTML <form> element.
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <form> <input type="button" onclick="window.location.href = 'https://www.w3docs.com';" value="w3docs"/> </form> </body> </html>
Try it yourself
Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location.
Using button tag inside <a> tag: This method create a button inside anchor tag. The anchor tag redirect the web page into the given location.
Adding styles as button to a link: This method create a simple anchor tag link and then apply some CSS property to makes it like a button.
Using form tags: This method uses form tag and button tag. When button is clicked then the form action attribute is called and web page redirect into the given location.
Note: The output will be same for every method.
HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.
Also Read: How to Enable and Disable Macros in Excel?