5 Ways To Create HTML Button Links (Simple Examples)

Welcome to a tutorial on how to create HTML button links. Text links work great, but they sure are painful on small mobile screens. To create an HTML “button link”, simply wrap the button in anchor tags – . But there are other ways to do it – Read on for the examples!

 

 

TABLE OF CONTENTS

 

DOWNLOAD & NOTES

Here is the download link to the example code, so you don’t have to copy-paste everything.

 

EXAMPLE CODE DOWNLOAD

Click here to download | Example on CodePen

The example code is released under the MIT license, so feel free to build on top of it or use it in your own project.

 

SORRY FOR THE ADS…

But someone has to pay the bills, and sponsors are paying for it. I insist on not turning Code Boxx into a “paid scripts” business, and I don’t “block people with Adblock”. Every little bit of support helps.

Buy Me A Coffee Code Boxx eBooks

 

 

 

TUTORIAL VIDEO

 

1) WRAP BUTTON IN ANCHOR TAGS


  
  • It is not a secret that we can wrap images in anchor tags.
  • So yes, we can also wrap buttons in anchor tags to create “button links”.

 

2) JAVASCRIPT REDIRECT

This is another easy way to create a button link.

  • 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.

 

 

3) SUBMIT FORM

A “creative way” to use forms. This example will submit an empty form, which effectively acts like a link.

  • action="URL" Redirect the user to where you want.
  • target="_blank" Optional, open in a new tab. If this is not defined, it will default to target="_self" and open in the same window.

 

4) FORM ACTION

A quick follow up of the previous example:

 

 

5) TURN LINK INTO BUTTON WITH CSS




  Code Boxx

Finally, turn the link to look like a button using some simple CSS.

 


 

 

WHICH IS THE BEST METHOD?

  • Personal preference – Just wrap the button in anchor tags or turn the link into button using CSS.
  • These 2 methods are also the most commonly used.
  • Javascript and form submit works, but these are considered “funky” and not good for search engine optimization (SEO).

 

LINKS & REFERENCES

 

INFOGRAPHIC CHEAT SHEET

How To Create HTML Button Links (click to enlarge)

 

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!

Leave a Reply

Your email address will not be published. Required fields are marked *