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
by

3 Answers

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

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

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=" //google.com"> analogous with the <a> element, but unfortunately no, this attribute does not exist according to HTML specification.
Bharatv4tg1
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 example.com'">
www.example.com
</button>
sandhya6gczb
sample code to do this

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

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.