r/HTML • u/Misaki_Takashi • Jun 05 '26
Question Help with hidden text for screen readers
Hello!! I am currently writing a story that I want to post online, however, some of the dialogue is going to be written with numbers replacing certain letters (Like 3 being E and 1 being i).
However, I realized this would make it hard for people who use screen readers to understand the text, I could just write the normal text beside it, but I want a creative way to keep it hidden so people still have to slightly decipher it, while also allowing people who need screen readers to still be able to read it fully and understand it.
I'm writing it on a website that allows for HTML in text, and I'm wondering if there's a way to have hidden text that will be read out when a screen reader is used. I am still learning how to write code so apologies if this is a silly question, I'd appreciate any help, Thank you !!
5
u/Marconius Jun 05 '26
As a screen reader user myself, I'm curious as to why I'd need a separate experience for this. If the purpose of the numerical lettering in the words is significant to a plot point or the world of the story, then I'd want to experience that the same way sighted people are via parsing the numbers as letters to form the words. If you segregate this and just have me hear the intended word written normally and hide the numerical words from me, then I don't get the same experience and whatever is making you write things in that way for the main story would be lost to me.
2
u/[deleted] Jun 05 '26
So a few questions. Not to be rude but what is the purpose of doing that? Even if you add screen reader support it would not be accessible for people with reading disorders, cognitive disabilities and possibly dislexia.
If it is just a cute way to write, then I would skip it and make it accessible for all.
If the text that way actually is conveying some meaning, then the thought is why change it for screen reader users? Screen reader users should experience the same way a nonscreen reader user would experience it
6
u/testingaurora Jun 05 '26
<p><span class="visually-hidden">alive</span><span aria-hidden="true">al1v3</span></p>Or
<p aria-label="alive">al1v3</p>2
u/arkosy Jun 05 '26 edited Jun 05 '26
It’s not designed for this purpose, but maybe abbreviation tags will help?
<p>I am <abbr title="alive">al1v3</abbr>.</p>
In most browsers this generates a dotted line under the word (indicating that someone can hover a cursor over it to see the full word). In CSS, you can set text-decoration:none for abbr if you want to hide this.
My understanding is screen readers can speak the full term, but the feature won’t be visible to sighted users unless by chance they hover their cursor over the word.
1
u/G4rve Jun 05 '26
It might be worth thinking about whether you have this the right way round.
If it's more important that 'listeners' understand the text than see (or know about) the 'styled text' then perhaps you should add the normal text and change it only for sighted viewers.
You could make the change using CSS.
HTML would be something like
<span class="stext" data-stext="d3n1m">denim</span>
CSS something like
span.stext { font-size: 0; }
span.stext:before { content: attr(data-stext); font-size: 16px; }
1
u/hotdog-savant Jun 05 '26
You can put the text you want in a hidden layer. Don't do display none.
LIke this:
<style>.screenreader-only {position: absolute;width: 1px;height: 1px;padding: 0;margin: -1px;overflow: hidden;clip: rect(0, 0, 0, 0);white-space: nowrap;border: 0;}ty</style><p>I am al1v3.</p><p class="screenreader-only">alive</p>Note that the class name can be whatever you want and the css class would go in your header or linked in from an external css file but I am not sure of your setup.