3 ms·
> you should never use a div as a button, it is an accessibility nightmare Eh, that's easily fixable with role="button" and tabindex="0". Oh, and adding a key
by chuckadams 3y ago
> you should never use a div as a button, it is an accessibility nightmare
Eh, that's easily fixable with role="button" and tabindex="0". Oh, and adding a keyup handler so space and enter both click it. After that though, you have a perfectly good button. Well, minus any visual feedback that it's being clicked, but presumably you're doing some custom effect to go with the custom element...
So never say "never", but yeah, use a damn <button> whenever you have the choice. The roles are there to give you an escape hatch when you don't. And sometimes buttons are actually just button-shaped links, in which case you _really_ want to use an <a> tag, because those are heinous to imitate properly.