Html creating buttons link

How can I add link to other pages for each of those buttons for example. If I click on: Get support button, it will redirect me to the support page which I already created.

6 Answers 6

You can then style it to look at much like a button as you like (although I note that most of the CSS you are applying to your elements is geared at making it look unlike a button. About the only thing you are likely to need to do to it is display: inline-block; text-decoration: none; color: black ).

Читайте также:  Вычисление функции на php

+1 Maybe you can add that it can be done using JavaScript, or adding a

tag with , if the OP wants the same style as the has.

You can go with this method to create a link-able button if you like.

This is not styled though

Well he did mention «html» didn’t specify if he wanted to use CSS to style it or use JavaScript to fire it so this is a simple method. No need for the passive aggressive comment

I mean the method attribute on the form should be GET or POST, as in the HTTP methods. LINK is not valid

you can style the button with CSS, using image buttons tend to be unresponsive.

If the only reason you want a tag is style, you can easily style tag

If you absolutly want to use a tag you could do it using javascript like so :

Nevertheless, keep in mind that using a button is not proper code, they are not dedicated to links

Use the a tag for links. For example :

Also, add display:inline-block in the css if you are using the a tag instead of the button tag.

Apparently your button is intended within table elements, to combine the intended styling and have it function as a link you may want to wrap [the button] a DIV inside of «Anchor» tags (). Below indicates a page called «bikes.html» as the linked element.

There are details though about using the tag which may not really be what you want and I usually use tags for this type of thing. But the anchor is what you’re missing.

interesting, I tested it and it did appear to work though the cursor remained an arrow, not a pointer which is why I suggested using a div instead. What about it is actually «forbidden»?

Good to know Pé Bin. I’m sick over constantly getting points taken away for attempting to help people here. Seems that so many are quick to downgrade and IMO they’re abusing the power. If someone’s answer is off-topic or flaming hatred is one thing but being chased away for technicalities doesn’t strike me as in the spirit of stack. I need some positive points! I looked at w3 and couldn’t find anything explicit forbidding button elements in a elements and even suggested in my answer that it wasn’t my preference for this solution.

I am sorry you feel the downvote is harsh, but its not valid markup: stackoverflow.com/a/6393863/2312574

Источник

How to Add an HTML Button that Acts Like a Link

There are several ways of creating an HTML button, that acts like a link (i.e., clicking on it the user is redirected to the specified URL). You can choose one of the following methods to add a link to the HTML button.

Add an inline onclick event

You can add an inline onclick event to the tag.

Example of adding an onclick event to the tag:

html> html> head> title>Title of the document title> head> body> button onclick="window.location.href='https://w3docs.com';"> Click Here button> body> html>

It is also possible to add an inline onclick event to the tag within the element.

Example of adding an onclick event to the tag:

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>

Use the action or formaction attribute.

Another way of creating a button that acts like a link is using the action or formaction attribute within the element.

Example of creating a button acting like a link with the action attribute:

html> html> head> title>Title of the document title> head> body> form action="https://www.w3docs.com/"> button type="submit">Click me button> form> body> html>

To open the link in a new tab, add target=»_blank» .

html> html> head> title>Title of the document title> head> body> form action="https://www.w3docs.com/" method="get" target="_blank"> button type="submit">Click me button> form> body> html>

Since there is no form and no data is submitted, this may be semantically incorrect. However, this markup is valid.

Example of creating a button acting like a link with the formaction attribute:

html> html> head> title>Title of the document title> head> body> form> button type="submit" formaction="https://www.w3docs.com">Click me button> form> body> html>

The formaction attribute is only used with buttons having type=»submit» . Since this attribute is HTML5-specific, its support in old browsers may be poor.

Add a link styled as a button with CSS properties. A href attribute is the required attribute of the tag. It specifies a link on the web page or a place on the same page where the user navigates after clicking on the link.

html> html> head> title>Title of the document title> style> .button < background-color: #1c87c9; border: none; color: white; padding: 20px 34px; text-align: center; text-decoration: none; display: inline-block; font-size: 20px; margin: 4px 2px; cursor: pointer; > style> head> body> a href="https://www.w3docs.com/" class="button">Click Here a> body> html>

Let’s see one more example.

html> html> head> title>Title of the document title> style> .button < display: inline-block; padding: 10px 20px; text-align: center; text-decoration: none; color: #ffffff; background-color: #7aa8b7; border-radius: 6px; outline: none; transition: 0.3s; > .button:hover < background-color: #c2c7c7; > style> head> body> a class="button" href="https://www.w3docs.com/learn-html/html-button-tag.html">HTML button tag a> body> html>

How about the accessibility?

Let’s take accessibility into our account for the last example. Here are some improvements to make the code more accessible:

If the button contained an image, it would be important to provide an alt attribute to make the image accessible to screen readers. Since this button doesn’t have an image, we don’t need to worry about this.

Adding a label to the button will help users who rely on assistive technology understand the purpose of the button. We can do this by wrapping the button text in a element and adding an aria-label attribute to the button.

To improve visibility for users with low vision, we can increase the contrast between the text color and background color of the button. We can achieve this by making the background color darker or the text color lighter.

Adding a focus style to the button will help users who navigate using the keyboard to see which element is currently focused. We can add a simple border to the button to achieve this.

Here’s the updated code with these improvements:

html> html> head> title>Title of the document title> style> .button < display: inline-block; padding: 10px 20px; text-align: center; text-decoration: none; color: #ffffff; background-color: #3c5d6e; border-radius: 6px; outline: none; transition: 0.3s; border: 2px solid transparent; > .button:hover, .button:focus < background-color: #c2c7c7; border-color: #7aa8b7; > style> head> body> a class="button" href="https://www.w3docs.com/learn-html/html-button-tag.html" aria-label="Learn about the HTML button tag">span>HTML button tag span> a> body> html>

Источник

How to Create an HTML Button That Acts Like a Link

How to Create an HTML Button That Acts Like a Link

Sometimes you may want to use a button to link to another page or website rather than to submit a form or something like that. This is fairly simple to do and can be achieved in several ways.

How to Create an HTML Button Using the Button Tag in an A Tag

One way is to simply wrap your tag in an tag:

This transforms your entire button into a link.

A second option is to create your link as you normally would with your tag and then style it via CSS:

Once you’ve created your link, you can the use CSS to make it look like a button. For instance, you could add a border, a background color, some styles for when the user is hovering the link.

How to Put a Button inside a Form Using HTML

Another way to add a button is to wrap an input inside form tags. Specify the desired target URL in the form action attribute.

I hope you’ve found tutorial helpful. Happy coding.

If this article was helpful, tweet it .

Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

freeCodeCamp is a donor-supported tax-exempt 501(c)(3) charity organization (United States Federal Tax Identification Number: 82-0779546)

Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons — all freely available to the public. We also have thousands of freeCodeCamp study groups around the world.

Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff.

Источник

Welcome to a quick tutorial on how to create HTML button links. Text links work great, but they sure are not catchy enough. Also on mobile devices, one with fat fingers may have a little trouble with tapping that small text link.

But there are actually several other ways to do so – Read on to find out!

ⓘ I have included a zip file with all the example source code at the start of this tutorial, so you don’t have to copy-paste everything… Or if you just want to dive straight in.

QUICK SLIDES

HTML Buttons As Links

TABLE OF CONTENTS

DOWNLOAD & NOTES

Firstly, here is the download link to the example code as promised.

QUICK NOTES

If you spot a bug, feel free to comment below. I try to answer short questions too, but it is one person versus the entire world… If you need answers urgently, please check out my list of websites to get help with programming .

EXAMPLE CODE DOWNLOAD

Click here to download the source code, I have released it under the MIT license, so feel free to build on top of it or use it in your own project.

All right, let us now get into the various ways to create a “button link” in HTML.

METHOD 1) JAVASCRIPT REDIRECT

  
  • The onclick property is used to specify what to do when the button is clicked.
  • location = ‘URL’ will set where to redirect to when the button is clicked.

P.S. You will notice that some other tutorials use location.href = ‘URL’ instead. That is not wrong and is the “old fashion” way of redirecting. Both will still work, location is a synonym of location.href .

METHOD 2) SUBMIT FORM

Who says that we can’t use forms in creative ways? The above will submit an empty form, which effectively acts just like a link. A couple of short notes for the absolute beginners:

  • Change the action=»URL» to redirect the user to where you want.
  • We can also add a target=»_blank» to open in a new tab. Otherwise if not defined, it will default to target=»_self» and open in the same window.
  • Take note that we are using here instead of – Submit will process the form when clicked, a button will not.

METHOD 3) FORM ACTION

The formaction is a property added in HTML5, and it is actually used to submit a form to an alternative URL. In the case of “button to link”, we can use it as a convenience to create multiple links in a single form.

The beauty of HTML and CSS – We can pretty much customize almost every element. Yes, we can even customize a link to look exactly like a button… But it is still essentially a link.

It is not a secret, we can wrap images in links. So yes, we can have the best of both worlds – Wrap buttons in links.

That’s all for this tutorial, and here is a small section on some extras and links that may be useful to you.

WHICH IS THE BEST METHOD?

Personally, I will either wrap the button in a link or use CSS to turn the link into a button. The main reasons are actually the ease of implementation, and for the purpose of search engine optimization (SEO). This might be a slightly advanced topic, but in short, we want to help search engines to find relevant links on the webpage as easily as possible.

For example, if we have a page about how to play the piano, we will want to include relevant links to other relevant piano pages… But here’s the problem – Search engines won’t necessarily follow all the Javascripts and forms to see where they lead to. So stick with using the traditional as much as possible.

YOUTUBE TUTORIAL

INFOGRAPHIC CHEAT SHEET

THE END

Thank you for reading, and we have come to the end of this guide. I hope that it has helped you with your project, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!

Источник

Оцените статью