Bad code
<button role="link" title="Name of website" tabindex="0">
<img alt="Name of website" src="logo.jpg" title="Name of website">
</button>
Issues and how to fix them
- Wrong usage of the button element. There’s an element for linking to external sites (
<a>
). Do not change native semantics, unless you really have to. - It’s possible to link to pages without JavaScript.
- The
title
attribute is redundant. - The
tabindex
attribute is redundant. A button doesn’t need tabindex
, it’s focusable by default.
Good code
<a href="https://">
<img alt="Name of website" src="logo.jpg">
</a>