bestbuildpc: Forums
 

 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do I create an HTML button that acts like a link?
 
 
Post new topic   Reply to topic    bestbuildpc Forum Index -> Web Development
View previous topic :: View next topic  
Author Message
bestbuildpc
Site Admin
Site Admin


Joined: Jun 30, 2012
Posts: 213
Location: NL

PostPosted: Mon Mar 27, 2023 1:51    Post subject: How do I create an HTML button that acts like a link? Reply with quote

HTML

How do I create an HTML button that acts like a link? So that clicking the button redirects the user to a page.

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

Code:
<form action="https://google.com"><a href="https://google.com" class="button">Go to Google</a>

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


CSS

If CSS is allowed, simply use an <a>


Code:
<a href="https://google.com" class="button">Go to Google</a>


a.button {
    -webkit-appearance: button;
    -moz-appearance: button;
    appearance: button;

    text-decoration: none;
    color: initial;
}



Or pick one of those many CSS libraries like Bootstrap.

Code:
<a href="https://google.com" class="btn btn-primary">Go to Google</a>



JavaScript

If JavaScript is allowed, set the window.location.href.

Code:
<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />
  
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    bestbuildpc Forum Index -> Web Development All times are GMT + 2 Hours
 
 Page 1 of 1

 

Jump to:   
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001-2008 phpBB Group
 
Forums ©