Accessibility · Junior · Question 8 of 75

Why use <button> rather than <div onclick>?

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.

Further reading

Problem with a question

Accessibility · Junior · question 8

Test yourself

Take the Accessibility · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz