Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use aria-label on a span

I'm showing product ratings using Unicode star symbols. iOS VoiceOver doesn't read this aloud correctly, so I thought I'd use aria-label on my span to tell screen readers what it means.

<span aria-label="4.0 stars out of 5, 123 ratings">★★★★☆ 4.0 (123)</span>

It's not working. iOS VoiceOver ignores my aria-label completely.

What am I doing wrong? How can I fix this?

like image 793
Dan Fabulich Avatar asked Dec 07 '22 13:12

Dan Fabulich


2 Answers

The aria-label is sometimes ignored by some assistive technology if the element you put it on doesn't have any semantic meaning. A <span> doesn't have semantic meaning. If you add a role that is appropriate for your stars, then it should be read correctly.

like image 74
slugolicious Avatar answered Dec 28 '22 19:12

slugolicious


One method would be to add a role=img

<span aria-label="4.0 stars out of 5, 123 ratings" role="img">★★★★☆ 4.0 (123)</span>
like image 41
Steve Faulkner Avatar answered Dec 28 '22 18:12

Steve Faulkner