you are looking for aria-describedby
.
This is used for adding additional information that is read out after semantically derived information.
<label for="input1">Label</label>
<input id="input1" aria-describedby="info-box-1">
<span id="info-box-1">Some Info</span>
In the example above it will read "Label" and then "Some Info"
Support and other issues
Warning - support for aria-describedby
is really not as good as you might think.
If information is truly important (i.e. the element will not make sense without it) then you should revert to using visually hidden text instead.
I have a Stack Overflow answer on the class you should use for visually hidden text instead of the built in sr-only
class in most libraries.
Please note there are certain times you cannot use this (i.e. within a <select>
s <option>
, but for essential information this is the only 100% supported way to do it (all the way back to IE6)
Note how in the following example I use aria-hidden
on the "some info" span to hide it and then add a visually hidden span directly within the label.
.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 */
}
<label for="input1">Label <span class="visually-hidden">,Some Info</span></label>
<input id="input1">
<span aria-hidden="true">Some Info</span>