Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 07-02-2025, 03:14 PM   #1
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 48
Karma: 10
Join Date: May 2025
Device: iPad
How to Hide Text from the Visual DOM but Keep It for Screen Reader?

I have some diagrams which need extensive description for visually impaired reader to have proper ARIA support. For that reason I use aria-describedby:

Code:
<div class="diagram">
  <figure>
    <img src="../images/diagram.png" aria-describedby="diag-description"/>
  </figure>
  <span id="diag-description" class="sr-only">The image is a diagram titled “Aloha from Hawaii”. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span>
</div>
Since the description is only required for screen reader I want to hide it completely from from the visual DOM. I've tried the following approach, but in Google Play Books this leads to akwardly 20 blank following pages after the diagram:

Code:
.sr-only {
  position: absolute;
  display: inline-block;
  width: 1px;   /* problematic */
  height: 1px;  /* problematic */
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0, 0, 0, 0);
}
The culprit seems to be the attempt to set width and height. Now as a first solution I've just stripped these properties:

Code:
.sr-only {
  position: absolute;
  display: inline-block;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0, 0, 0, 0);
}
But that seems no proper solution for me, since it relies heavily on clip which might not be supported in many reader.

What is the common solution to hide text from the visual DOM but keep it alive for the accessibility DOM?

Many thanks in advance for any help.
Slevin#7 is offline   Reply With Quote
Old 07-02-2025, 03:36 PM   #2
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,734
Karma: 5703586
Join Date: Nov 2009
Device: many
What happens when you add the hidden attribute or display:None?
KevinH is online now   Reply With Quote
Advert
Old 07-02-2025, 03:43 PM   #3
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 48
Karma: 10
Join Date: May 2025
Device: iPad
Hidden will keep the assigned space but won't display the text, which may lead to a very atrocious design. Display none will strip the content completely from the DOM both the visual and the accessibilty one.
Slevin#7 is offline   Reply With Quote
Old 07-02-2025, 03:51 PM   #4
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,734
Karma: 5703586
Join Date: Nov 2009
Device: many
Why assign it any space? The visibility:hidden css style does but what about the hidden attribute. The hidden="hidden" attribute should not still allocate space on the page.

Or perhaps do the reverse. Use the aria hidden="true" on the normal displayed text that describes the page and add an aria label instead of aria-describedby to prevent duplication.

Perhaps try absolute positioning off the screen. Or try setting the foreground color to the background color and shrink font size to be tiny. A an accessibility reader should have no trouble reading text taken from the dom no matter the css specified font size.

Last edited by KevinH; 07-02-2025 at 04:15 PM.
KevinH is online now   Reply With Quote
Old 07-02-2025, 04:38 PM   #5
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 48
Karma: 10
Join Date: May 2025
Device: iPad
The hidden attribute (directly set inside the tag) seems to behave similar to display none regarding accessibility concerns with the result that the text will not be read by the screen reader. (tested with Thorium)
Slevin#7 is offline   Reply With Quote
Advert
Old 07-02-2025, 04:44 PM   #6
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 48
Karma: 10
Join Date: May 2025
Device: iPad
Quote:
Originally Posted by KevinH View Post
Perhaps try absolute positioning off the screen.
I can do this with maybe top: -9999px;
Since I don't have experience with that I'd like to ask if that solution comes with any downsides?

Quote:
Originally Posted by KevinH View Post
Or try setting the foreground color to the background color.
Color settings won't get honored by all readers, some do, some don't. Especially when the user selects the theme by hand.

Quote:
Originally Posted by KevinH View Post
shrink font size to be tiny.
Many reader have a minimum font size setting, which you can't undermine.

Anyhow, thank you very much all these advices.
Slevin#7 is offline   Reply With Quote
Old 07-02-2025, 05:12 PM   #7
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,734
Karma: 5703586
Join Date: Nov 2009
Device: many
FWIW, the Thorium ScreenReader is not the same as a real Accessibility Reader. So you have one more type of reader to worry about. Surely just using an aria-label attribute would only be read by real accessibility readers and not screen readers.
KevinH is online now   Reply With Quote
Old 07-03-2025, 05:10 PM   #8
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 13,935
Karma: 103895653
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
I'm obviously a confused idiot. If an image has alt-text I never see it, but isn't it always read by a screen reader?
Quote:
The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).
https://www.w3schools.com/TAGS/att_alt.asp

As an aside why didn't the original 1999 pre-epub2 (or epub2) implement the simple client side image map? Though limited use except for "plot your own adventure" type novels.

I've not read these links on the subject. https://www.w3.org/WAI/alt/

I always put alt text on any image needing it. I'd not put it on a QR code for a URL that has the QR code URL in text exactly visible.

I test TTS on Pocketbook on Android.
Quoth is offline   Reply With Quote
Old Yesterday, 04:11 AM   #9
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 48
Karma: 10
Join Date: May 2025
Device: iPad
Quote:
Originally Posted by Quoth View Post
I'm obviously a confused idiot. If an image has alt-text I never see it, but isn't it always read by a screen reader?
You're right, the alt attribute gets perfectly read and is only shown visually as a fallback when the image can't be presented.

However, regarding to WCAG it should only be used for short descriptions, while long descriptions should be provided via aria-describedby: https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA15

The recommended maximum size of characters for the alt attribute seems to be round about 125, though theoretically there is no limit.

To go with the recommendations and assuming WCAG knows why and what I will stick with aria-describedby for long descriptions, I my case over 1000 chars. But unfortunately they don't provide a common solution how to hide the element which contains the description.
Slevin#7 is offline   Reply With Quote
Old Yesterday, 09:01 AM   #10
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,734
Karma: 5703586
Join Date: Nov 2009
Device: many
What about aria-label? It has no size limit that I know of? But neither does alt? Hell I have seen data-attributes with 5k long strings in them.

AFAICT aria-describedby is meant to be used when a description for the image is already in an existing node. It is meant to point to h1-h6 tags or a div or p that is meant to be visible to all. That way redundant pieces of text are not created for the accessibility reader.
KevinH is online now   Reply With Quote
Old Yesterday, 10:06 AM   #11
Slevin#7
Enthusiast
Slevin#7 began at the beginning.
 
Posts: 48
Karma: 10
Join Date: May 2025
Device: iPad
Quote:
Originally Posted by KevinH View Post
What about aria-label? It has no size limit that I know of? But neither does alt? Hell I have seen data-attributes with 5k long strings in them.
aria-label might be a viable solution, since it doesn't interfere with the alt-attribute and is a dedicated accessibility purpose attribute. I'll give it a try, thanks for the tip.
Slevin#7 is offline   Reply With Quote
Old Yesterday, 01:38 PM   #12
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,746
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Quote:
Originally Posted by Slevin#7 View Post
I have some diagrams which need extensive description for visually impaired reader to have proper ARIA support. For that reason I use aria-describedby:

Code:
<div class="diagram">
  <figure>
    <img src="../images/diagram.png" aria-describedby="diag-description"/>
  </figure>
  <span id="diag-description" class="sr-only">The image is a diagram titled “Aloha from Hawaii”. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span>
</div>
Since the description is only required for screen reader I want to hide it completely from from the visual DOM.

What is the common solution to hide text from the visual DOM but keep it alive for the accessibility DOM?

Many thanks in advance for any help.
Watch the epub I attach; there I give you a possible solution to your issue. You would need to employ in your .xhtml file the following code:

Code:
  <div>
    <figure>
      <img src="../Images/balloon.jpg" aria-describedby="diag-description"/>

      <div id="diag-description" class="sr-only">
        The image is a diagram titled “Aloha from Hawaii”. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </div>
    </figure>
  </div>

  <p>This is a dummy text to see if the "aria-describedby" is hidden but active.</p>
And you would need to style it as following:

Code:
figure {
  width: 100%;
  margin: 0;
}

img {
  width: 100% !important;
  margin: 1em 0;
}

.sr-only {
  position: relative; 
  z-index: -1;
  display: block;
  width: 100%;
  line-height: 0px !important;
  margin-top: -2em; /* here you can play with the value */
}
The text you are trying to hide is not vissible but a TTS system will read it. Do your test in Thorium.
Attached Files
File Type: epub aria-describedby.epub (23.0 KB, 4 views)

Last edited by RbnJrg; Yesterday at 01:40 PM.
RbnJrg is offline   Reply With Quote
Old Today, 10:02 AM   #13
RbnJrg
Wizard
RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.RbnJrg ought to be getting tired of karma fortunes by now.
 
Posts: 1,746
Karma: 8700123
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
Here you have an even better solution; I tested it on Thorium and Calibre Viewer and works as expected.
Attached Files
File Type: epub aria-describedby Bis.epub (23.1 KB, 2 views)

Last edited by RbnJrg; Today at 10:20 AM.
RbnJrg is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make text single space, but still wrap to reader screen crankypants Sigil 8 11-04-2015 10:13 AM
K3 - Hide dictionaries on home screen? SweetBearCub Amazon Kindle 5 06-06-2014 05:36 PM
Glo hide the footnote / endnote text shown in note preview fxp33 Kobo Reader 3 05-04-2013 08:11 PM
Hide dictionaries from home screen morrow Amazon Kindle 4 10-07-2012 07:03 PM
How much text can we cram onto the screen of an e-reader? pavelh Which one should I buy? 5 06-14-2010 02:45 PM


All times are GMT -4. The time now is 04:32 PM.


MobileRead.com is a privately owned, operated and funded community.