How do I create an HTML button that acts like a link? So that clicking the button redirects the user to a page.
I want it to be accessible, and with minimal extra characters or parameters in the URL.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
HTML
The plain HTML way is to put it in a
<form>wherein you specify the desired target URL in theactionattribute.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="https://google.com">analogous with the<a>element, but unfortunately no, this attribute does not exist according to HTML specification.CSS
If CSS is allowed, simply use an
<a>which you style to look like a button.Or pick one of those many CSS libraries like Bootstrap.
Noted should be that, historically, the CSS
appearance:buttonproperty worked as well in some browsers, but this was experimental and ended up being considered a misfeature. Onlynoneorautoare allowed on<a>elements.JavaScript
If JavaScript is allowed, set the
window.location.href.Instead of
<input type="button">in above example, you can also use<button>. The only difference is that the<button>element allows children.