Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use a button (<button>) or a link (<a>) in HTML?

Tags:

html

I was reading the Bootstrap documentation about the button tags (http://getbootstrap.com/css/#buttons-tags), as <button> and <a> tags have exactly the same appearance, and I found this :

Cross-browser rendering

As a best practice, we highly recommend using the <button> element whenever possible to ensure matching cross-browser rendering.

What is the reason that can lead me to use a <button> tag (which doesn't have a href attribute) instead of a <a> for navigation ?

Maybe <button> is better when designing web applications when it interacts with the page itself, and of course for submitting forms, but is it all ?

[this question is related to SEO: <button> vs <a> HTML tags but the question is not the same]

like image 514
Mickaël Avatar asked Feb 11 '14 23:02

Mickaël


People also ask

When to use button vs link HTML?

UX Movement wrote an article about this, and they came up with a simple rule: Buttons are used for actions that affect the website's front-end or back-end; links are used for navigation and actions that don't affect the website at all. The line between buttons and links can be blurry.

Should Download be a link or button?

A hyperlink is correct and expected behaviour. As your link text contains the word "download" there will be no confusion, you do not need to do anything else.

Should I use button tag or a tag?

use a <button> when you don't need to navigate for example loading a modal or submitting a form, always use <a> for navigation.

Is it OK to have a link that looks like a button?

Answer. Yes, it is OK to use links that look like buttons, but it is highly encouraged to use the native elements if possible. If necessary you can have links that look like buttons and you can even do the opposite and make link elements function as buttons.


1 Answers

Thanks to the comments on my question, this is the answer I believe to be true :

I have to use <a> for links and navigation between page / views.

I have to use <button> for actions, for example on the current page : validating/resetting a form, showing a modal...

like image 127
Mickaël Avatar answered Oct 11 '22 20:10

Mickaël