HTML & CSS · Junior · Question 41 of 75
When should you use <a> and when <button>?
- 1It doesn't matter: they're styled the same way and behave the same too
- ✓Correct answer:
<a href>to navigate to a URL,<button>for an action on the page - 3
<button>only inside forms; links for every other clickable element
Explanation
Links and buttons behave differently and have different semantics for screen readers: a link can be opened in a new tab and copied, and it activates with Enter; a button activates with Enter and Space. A <div onclick> instead of a button breaks keyboard accessibility. Buttons are fine outside forms with type="button".