Not satisfied by the Answer? Still have doubts?
Ask Question

How to create HTML button that acts like a link?

I want to create an HTML button that acts as a link. So, when you click the button, it redirects to a page. I would like it to be as accessible as possible.
I would also like it so there aren't any extra characters or parameters in the URL.
How can I achieve this?
hyperlink button html

3 Answers

The plain HTML way is to put it in a <form> wherein you specify the desired target URL in the action attribute.

<form action=" //">
<input type="submit" value="Go to Google" />

If necessary, set CSS display: inline; on the form to keep it in the flow with the surrounding text. Instead of <input type="submit"> in above example, you can also use <button type="submit">. The only difference is that the <button> element allows children.

You'd intuitively expect to be able to use <button href=" //"> analogous with the <a> element, but unfortunately no, this attribute does not exist according to HTML specification.
In the event that you are utilizing an inside structure, add the trait type="reset" alongside the catch component. It will forestall the structure-activity.
<button type="reset" onclick="location.href='http'">
sample code to do this

<button formaction="url">Go </button>

Login / Signup to Answer the Question.

  • Be descriptive with your answer, and try to avoid copy-pasting external links, instead guide the user who has asked the question, where can they find the detailed answer.
  • You cannot share any URL in answer.
  • To make a text bold, surround the text with single asterisk, for example *bold text*
  • To format a text like code, surround the text within double asterisk, for example **code**
  • To add a multiline piece of code, surround the whole code within triple asterisk, for example *** multiline code ***
  • Please verify before submitting the answer.