HTML & CSS · Junior · Question 41 of 75

When should you use <a> and when <button>?

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".

Further reading

Problem with a question

HTML & CSS · Junior · question 41

Test yourself

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

Take this quiz