Accessibility · Junior · Question 8 of 75
Why use <button> rather than <div onclick>?
- 1It brings focus, keyboard activation and a role for free
- 2A
divcan't have a click handler at all - 3It renders faster because browsers optimize buttons
Show the answer
Correct answer: It brings focus, keyboard activation and a role for free
Explanation
A native button is focusable, works with Enter and Space and is announced as a button. A div needs tabindex, role and key handlers to imitate that, and it's easy to get wrong.