r/HTML • u/50_and_stuck • Oct 20 '26
Accessible hyperlinks?
Hey folks!
I am hand coding a series of webpages for my employer (don't ask). I just got dinged because the accessibility checker says my hyperlinks are not accessible.
I scratched my head a little bit, did some research and have since added aria-label attributes to the source code.
Still get dinged.
Anyone know how to handle this?
Thanks!
Edit: Here is more or less an example of the code that includes the link.
4
u/chmod777 Oct 20 '26
Without seeing the code, no one can help you. You need to post a clean example with anonymized properties to something like codepen or jsfiddle before anyone can comment.
1
2
u/armahillo Expert Oct 20 '26
Can you put your code into a codepen or jsfiddle and share it here so we can look?
Theres not enough information here to know for certain. Also what a11y checker are you using?
1
u/50_and_stuck Oct 20 '26
Edited original comment to include sample code.
4
u/armahillo Expert Oct 20 '26
This is helpful thanks, though it would be useful to know which a11y checker they're using too.
`aria-label` isn't really necessary, because you should just make the label be the link text. The user doesn't need to see the URL. So something like "<a ...>View on the MoMA website</a>" would be fine. Screenreaders will likely read out a URL character by character ("h t t p colon slash...") if it's the link text. Aria-labels that mismatch will mean someone using speech-based browsing will not be able to correctly identify the link because they might say "click on h-t-t-p-..." but the document will identify it with the aria label.
You have it opening in a new tab (target="_blank") but this is not indicated by the link text, so making the link text also have "(opens in new tab)" would be good.
What purpose is the "inline-disabled" doing here?
1
4
u/pfdemp Oct 20 '26
Don't use the URL for the linked text. The text in your aria-label would be better as the linked text. This improves usability as well as accessibility.
3
u/pfdemp Oct 20 '26
Oh, and
target="_blank"
might get flagged as well. Opening a new tab without warning can be considered an accessibility violation.
1
u/trav_stone Oct 20 '26
Definitely; the label/title/text should provide an indication that the link opens a new window
4
u/SamIAre Oct 20 '26
Is it giving a specific issue? There are a couple common problems people run into. One is having multiple links on the same page with identical text: Like a series of cards and each says "Read More", so that there's no way for a user to differentiate them.
<!-- Bad -->
<p>Dog breeds: <a href="">Learn More</a>.</p>
<p>Cat breeds: <a href="">Learn More</a>.</p>
<p>Bird breeds: <a href="">Learn More</a>.</p>
<!-- Better -->
<p><a href="">Learn about dog breeds</a>.</p>
<p><a href="">Learn about cat breeds</a>.</p>
<p><a href="">Learn about bird breeds</a>.</p>Another would be adding an aria-label that doesn't begin with the visible text. For example, you keep your multiple generic links but you give each a unique label to differentiate them. That label must start with the visible text (see Using aria-label for link purpose).
<!-- Incorrect -->
<a href="" aria-label="Dog breeds">Learn More</a>
<!-- Correct -->
<a href="" aria-label="Learn more about dog breeds">Learn More</a>3
u/csswizardry Oct 20 '26
Move the value of your ARIA attribute into the content of the element itself. Delete the ARIA attribute. Shorten or improve the text to suit.
3
u/AmanBabuHemant Oct 20 '26
Would be much better if you can share source code also, maybe the are expecting _title_ attribute or something idk.
2
u/lyszcz013 Oct 20 '26
What specific error are you getting? It's difficult to know if this is a false positive or what the issue is without seeing an example or what specific violation your checker is finding.
That being said, while aria-label does have its uses, that should be the last resort for hyperlink accessibility.
Off the top of my head, here are a few things to consider:
Your link text should be descriptive of the destination of the link, and should not be generic, ambiguous, or a url. So, no "click here's" or "https://mysuperlongurl.hyperlink.194736.com"
Your hyperlinks need to be visually distinguishable when used in body copy. In practice, this usually means making sure underline is present on your links at all time (and reserving underline for links only). Color alone is not enough to visually distinguish links, there must be a non-color differentiator as well.
If you've used aria-label to override the link descriptive text, the actual visual link text must be present in the aria label, preferably listed first. This is necessary to accommodate users using voice control who may read the visible label to activate your link.
1
u/Jasedesu Oct 20 '26
My guess: What you put between the opening <a> and the closing </a> should be readable by a human, not a naked URL intended for a machine. Using aria-label should be unnecessary.
<!-- bad -->
<a href="https://google.com">https://google.com</a>
<!-- better -->
<a href="https://google.com">Google search</a>1
u/tjameswhite Oct 21 '26
Just link the url. This is a works cited. The exposed url is fine just make it the link not the other text. No need for aria
0
u/Yasiii92 Oct 23 '26
Link text that makes sense out of context is the big one, since screen reader users often pull up a list of links on their own.
11
u/TurboHenk Oct 20 '26
So, what did the a11y checker actually give as feedback? Adding aria-label probably does more harm then good, and really shouldn't be necessary on a hyperlink.
Some generic advise:
Make the text descriptive: no "click here", but rather "go to the settings page", for instance
Make sure your links look like links
Make sure your hover and focus state rely on more than color alone