I have the below HTML where part of the text is colored red. This is to visually draw attention to the text.
<div>
<span style="color:red">Note: </span>
<span>Don't forget your appointment.</span>
</div>
When I swipe right through this using VoiceOver it’s read as:
swipe note
swipe don’t forget your appointment
However, it doesn’t make sense to make someone swipe twice to hear this message.
What I want is for this text to be read as a single element by Voiceover, the same as if the HTML was:
<div>
Note: Don't forget your appointment.
</div>
Other styles, such as bolding a word in the middle of a sentence, also cause this issue.
2
Answers
I figured out one possible solution. The way to fix this is to add the non-standard text role:
This is, apparently, only recognized by iOS. However, I found that Android's TalkBack doesn't have this issue to begin with. It knows to read the line as a single item.
CAREFUL: this will also read across embedded links so they can't be activated.
There is nothing accessible about your html.
To make this accessible firstly use semantic html – ie html elements that describe their function, like p for paragraph, or h1 – h6 for heading and so on.
example.html
You can use styles to make it more visually appealing for most users, but visually impaired users may not see the colour, especially if they are using a screen reader.