Reputation: 5431
What's good practice for <button>
?
Can it replace <a>
tag or is it only meant for forms?
Upvotes: 4
Views: 1394
Reputation: 10231
A link links to something - at least it should! It is semantically wrong to do the following:
<a href="#" onclick="doSomething(); return false;">Do something</a>
This should be replaced with a button, as it is there for that purpose - it works as a trigger for something the user (programmer) specifies; the purpose of a <button type="button">
element is thus not clear. In contrast, the purpose of a link is very clear - it should point somewhere!
As HTML is a markup language, it does not matter all that much what you do, if you do not think SEO. You can achieve the same thing with a <a>
tag as you can with a <button>
tag, like a <span>
can act exactly as a <div>
- semantically though, it is incorrect.
Upvotes: 5
Reputation: 63596
A <button>
is for form elements only. In Opera you navigate links with a, q and Ctrl+Arrow, form elements are accessible per tab.
So, no, you shouldn’t replace one element with the other.
Upvotes: 1
Reputation: 146630
If you want to use a <button>
tag to replace a regular link (<a href="...">
) you'll have the following disadvantages:
I can't think of any advantage right now.
Upvotes: 1
Reputation: 34011
Depends on company conventions really, but with my experience buttons
are typically used when the page does not redirect (including, but not limited to forms), and an <a>
for when the user is directed to a new page.
Upvotes: 2