The Golden Rule
- Links (
<a>): Go somewhere. They change the URL or navigate to a page anchor. - Buttons (
<button>): Do something. They trigger an action (submit form, open modal, toggle menu).
Why It Matters
- Key Bindings: Links activate on
Enter. Buttons activate onEnterandSpace. - Expectation: Screen reader users expect links to take them to a new context and buttons to change the current context.
Common Anti-Patterns
- The "Link Button": Using a
<div>with anonClickhandler.- Fix: Use
<button type="button">.
- Fix: Use
- The "Button Link": Using a link with
href="#"to trigger JS.- Fix: Use
<button>.
- Fix: Use
Styling
You can make a link look like a button or a button look like a link using CSS, but the underlying HTML must match the behavior.