Just Use a Button
gomakethings.com·14w·

One of the weirdest “debates” I seem to perpetually have with framework-enthusiastic developers is whether or not a <div> is “just as good” as a <button>.

Spoiler: it’s not. Let’s dig in.

The problem

Among the React crowd, and also among people who seem to enjoy HTMX, I see a lot this…

<div onclick="showSignIn()">
Open Modal
</div>
function showSignIn () {
// Code to show the sign-in modal.
// The details of what happens here vary by stack.
}

What’s wrong with this?

  1. This element does not announce itself as an interactive element to screen reader users.
  2. You can’t focus on a <div> with a keyboard.
  3. The event only fires on click, not when the Enter or `Space Bar…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help