Date ranges are always a tricky thing as there isn't a better way than the one you are using (<p><time>01/06/2017</time> - <time>01/06/2018</time></p>
)
However there is a way you can force it to say "to", with a quick caveat:
If you use this method then if someone uses auto translate or you internationalise the site at some point it may result in poor translations / a lot of work converting the "to" to other languages.
With that disclaimer out of the way, the trick is to use the actual word "to": <p><time>01/06/2017</time> to <time>01/06/2018</time></p>
.
But I know what you are thinking, I don't want the word "to" to be visible, I want to use a dash visually.
So now we introduce visually hidden text
and aria-hidden
to display one thing but read out another:
<p>
<time>01/06/2017</time>
<span aria-hidden="true">-</span>
<span class="visually-hidden">to</span>
<time>01/06/2018</time>
</p>
What we have done is hide the dash from screen readers and then provide some screen reader only text to replace it (another name for "visually hidden" is "screen reader only")
Here is a fiddle demonstrating:
.visually-hidden {
border: 0;
padding: 0;
margin: 0;
position: absolute !important;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 - a 0 height clip, off to the bottom right of the visible 1px box */
clip: rect(1px, 1px, 1px, 1px); /*maybe deprecated but we need to support legacy browsers */
clip-path: inset(50%); /*modern browsers, clip-path works inwards from each corner*/
white-space: nowrap; /* added line to stop words getting smushed together (as they go onto seperate lines and some screen readers do not understand line feeds as a space */
}
<p>
<time>01/06/2017</time>
<span aria-hidden="true">-</span>
<span class="visually-hidden">to</span>
<time>01/06/2018</time>
</p>
Note: Trying to persuade a screen reader to say things a certain way is nearly always a recipe for introducing accessibility issues rather than fixing them. In this instance I think you are fine (hence why I gave an answer), but use this technique sparingly, most of the time screen reader users will be used to strange pronunciations and "fixing" them can actually be more confusing.
Although I have showed you how to "fix" this my personal opinion is that it does not need any intervention, it makes sense with "dash" being read out, but I also think you will not do any harm in this instance if you really want to try this technique out so I will leave the decision up to you.
-
`, is there any disadvantages to doing it this way vs the method you provided? – nix1016 Feb 22 '22 at 22:1401/06/2017 - 01/06/2018
` gets read out in one go, albeit wrongly. Is there any way to get the screen reader to read it out as a single line instead of fragments? As you said, it's not too big of an issue if it can't be done. – nix1016 Feb 22 '22 at 22:14