Links vs buttons
If it goes somewhere, it’s <a>
link.
- Even if it looks like big shiny button, it must be coded as
<a>
link - When the user clicks a link, they are taken to a different location (within the page, within the website or out to the greater WWW).
If it does something, it’s a <button>
- Buttons cause an action to occur on the same page
- Submit a form (even when submission takes you to a new page)
- Open a menu
- Launch a modal
- Expand details
- A button can look like a link, but it must be coded as a
<button>
Code examples
Use semantic HTML with common sense names
This semantic HTML contains all accessibility features by default.
This semantic HTML looks like a big shiny button, but it is still a link.
Name links logically
- Do not use a heading with a generic link below.
- Instead, make the heading a link.
What to do instead
Making a link with no href
focusable
- Do not put anything but a URI in the
href
- A link with no
href
will not be focusable with the keyboard withouttabindex="0"
. - Add
role="link"
to ensure screen reader reads the role
Avoid custom elements
This custom button requires extra attributes and keyboard event listeners.
Repeating text links
Sometimes the design will call for multiple links with the same text label. In a case like this, aria-label
can be used to name each link’s purpose.
Don’t duplicate the visible text name in the aria-label
Do not repeat the inner text content of a link in the aria-label
.
Don’t use javascript in href
- Do not use
"href="javascript:void(0)"
. - When screen readers read the href, it becomes confusing and nonsensical
Don’t use “#” in href
Disabled links
- If it’s unavoidable to have a disabled link present you’ll need these attributes for the screen reader.