Note: We've removed most classes to improve readability.
Bad code
<a tabindex="0" type="button" href="/signup" role="link">
<span class="focus" tabindex="-1"></span>
<span>
<span>
<span>Sign up</span>
<i class="icon icon-external-link" aria-hidden="true" role="img"></i>
</span>
</span>
</a>Issues and how to fix them
- You don’t need the
tabindexattribute if you use anatag. HTML hyperlinks are focusable by default. - The
typeattribute onatag is used to hint at the linked URL’s format with a MIME type, eg:type="image/svg+xml" - Using
role=linkon anatag is not needed since you already get that behaviour for free by using a standard hyperlink (<a href="">). - A negative
tabindexvalue means that the element is not accessible via keyboard, but it could be focused with Javascript - An additional
spanto handle focus isn’t necessary,acan do that by itself. 💪🏻 - The
ielement represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text.Footnote2 If you just want italic text, usefont-style: italic;in CSS. - If you’re using
aria-hiddenon an element, you don’t need to declare arole, because the element is inaccessible to screen reader users, anyway. - Try to avoid excessive DOM sizes. Too many DOM nodes and nested DOM elements may harm your page performance. A large DOM tree results in a large accessibility tree, which may have a bad impact on the performance of assistive technology. Only use extra
divs andspans, if the design demands it. - Icon option 1: While
aria-hiddencan be useful to hide content that is not needed for screen readers (in this case an icon image), it's useful to add anaria-labelwhen that content is meaningul for everyone, like declaring that an hyperlink will open in an external tab. - Icon option 2: The icon can be removed, because in the original snippet the link points to a page on the same site that opens in the same tab. The external link icon is intended to inform users that by clicking the link they’re leaving the site.
Check out the resources section at the bottom of this page for more.
Good code
<a href="/signup">
Sign up
<span class="fa fa-external-link" role="img" aria-label="External link">
</span>
</a>or
<a href="/signup"> Sign up </a>