What's good practice for <button>
?
Can it replace <a>
tag or is it only meant for forms?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With