What is good practice for the <button> button? Can it replace <a> or is it only for forms?

What is good practice for <button> ?

Can it replace the <a> tag or is it designed only for forms?

+4
source share
4 answers

Link to something - at least it should be! It is semantically incorrect to do the following:

 <a href="#" onclick="doSomething(); return false;">Do something</a> 

This must be replaced with a button, since it is for this purpose - it works as a trigger for what the user (programmer) indicates; therefore, the <button type="button"> element is not clear. On the contrary, the purpose of the link is very clear - it must point somewhere!

Since HTML is a markup language, it doesn't matter what you do if you don't think SEO. You can achieve the same with the <a> tag as you can, with the <button> , for example, <span> can act exactly like <div> - semantically, but this is not true .

+4
source

Depending on the agreements, companies are really, but with my experience, buttons are usually used when the page does not redirect (including, but not limited to forms), and <a> when the user is redirected to a new page.

+2
source

If you want to use the <button> to replace a regular link ( <a href="..."> ), you will have the following disadvantages:

  • It will not look like a link, so it will just add confusion.
  • You need to use JavaScript so that the button does something.
  • Search engines and other tools will not be able to follow the link.
  • You will not have a visual indication for the links you visit.
  • Users can no longer open the link in a new tab, check the destination, or copy the URL.

I can’t think of any benefits right now.

+1
source

A <button> is for form elements only. In Opera, you follow links with a , q and Ctrl + Arrow, form elements are available behind the tab .

So no, you should not replace one element with another.

+1
source

Source: https://habr.com/ru/post/1380644/


All Articles