Should a clickable thing be a button or a div with onclick
I am a designer moving into front end code, and I am rebuilding a pricing toggle from a design file. The developer before me wrote it like this:
Cite
CoursesWeb Forum, "Should a clickable thing be a button or a div with onclick", https://coursesweb.net/forum/t/should-a-clickable-thing-be-a-button-or-a-div-with-onclick/, accessed 2026-11-27.<div class="toggle" onclick="switchPlan()">Yearly</div>It looks right and works with a mouse. But when I test with only the keyboard, Tab skips straight past it, and Enter does nothing. Our screen reader test (VoiceOver) reads it as plain text "Yearly" with no hint that it does anything.
I could add tabindex="0" and a keydown listener, but that feels like rebuilding something that should already exist. Is there ever a good reason to use a div with onclick instead of a real button? And if I switch to
<button>, how do I get rid of the default grey browser styling without breaking anything?
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.