iTranslated by AI
Handling Screen Reader Announcements for dl/dt/dd
Unexpected Reading Behavior
As developers who have used screen readers know, the structure of dl, dt, and dd elements behaves differently than expected in screen reader announcements. This is likely due to historical reasons, and some developers seem to choose not to use these elements because of this behavior.
Current screen reader announcements generally behave as follows. The HTML comments represent the content being read out loud.
<dl>
<dt>Apple</dt>
<!-- List 1/4 Apple -->
<dd>A deciduous tree in the rose family</dd>
<!-- List 2/4 A deciduous tree in the rose family -->
<dt>Mandarin Orange</dt>
<!-- List 3/4 Mandarin Orange -->
<dd>An evergreen shrub in the citrus family</dd>
<!-- List 4/4 An evergreen shrub in the citrus family -->
</dl>
Looking strictly at the behavior, it is equivalent to the following code.
<ul>
<li>Apple</li>
<!-- List 1/4 Apple -->
<li>A deciduous tree in the rose family</li>
<!-- List 2/4 A deciduous tree in the rose family -->
<li>Mandarin Orange</li>
<!-- List 3/4 Mandarin Orange -->
<li>An evergreen shrub in the citrus family</li>
<!-- List 4/4 An evergreen shrub in the citrus family -->
</ul>
Well, your first thought is likely: This shouldn't be happening! In terms of the information tree, the descriptions are supposed to be nested under "Apple" and "Mandarin Orange." Treating it as a list with four items, where terms and descriptions are lined up flatly, is definitely wrong.
Try Removing the List Semantics
If it results in such confusing announcements, how about removing the behavior itself?
<dl role="generic">
<dt role="generic">Apple</dt>
<!-- Apple -->
<dd role="generic">A deciduous tree in the rose family</dd>
<!-- A deciduous tree in the rose family -->
<dt role="generic">Mandarin Orange</dt>
<!-- Mandarin Orange -->
<dd role="generic">An evergreen shrub in the citrus family</dd>
<!-- An evergreen shrub in the citrus family -->
</dl>
By specifying role="generic", you remove the roles implicitly defined for the dl, dt, and dd elements. Rather than "removing" them, it gives them the meaning of "having no special significance"[1]. In terms of the accessibility tree, it is equivalent to the following:
<div>
<div>Apple</div>
<!-- Apple -->
<div>A deciduous tree in the rose family</div>
<!-- A deciduous tree in the rose family -->
<div>Mandarin Orange</div>
<!-- Mandarin Orange -->
<div>An evergreen shrub in the citrus family</div>
<!-- An evergreen shrub in the citrus family -->
</div>
Now the reading is flat, but it is somewhat better than conveying a completely incorrect list structure.
Some might think, "Then why not just use div for everything from the start?" Well, I suppose that's just a markupper's ego. We want to use dl, dt, and dd elements. From the perspective of WAI-ARIA, they are generic, but from the perspective of HTML, a description list is a description list.
Leveraging the Fallback Property of the role Attribute
At this stage, this method works for screen readers, but leaving it as is would be problematic. This is because if screen reader announcements for description lists improve in the future, you wouldn't be able to benefit from those improvements if you keep this approach.
So, I thought about leveraging the property of the role attribute where multiple roles can be specified: the first one is prioritized, and subsequent ones act as fallbacks.
<dl role="associationlist generic">
<dt role="associationlistitemkey generic">Apple</dt>
<!-- Apple -->
<dd role="associationlistitemvalue generic">A deciduous tree in the rose family</dd>
<!-- A deciduous tree in the rose family -->
<dt role="associationlistitemkey generic">Mandarin Orange</dt>
<!-- Mandarin Orange -->
<dd role="associationlistitemvalue generic">An evergreen shrub in the citrus family</dd>
<!-- An evergreen shrub in the citrus family -->
</dl>
associationlist, associationlistitemkey, and associationlistitemvalue are new roles appearing in the latest WAI-ARIA draft (corresponding to version 1.3)[2]. They are intended to correspond to the dl, dt, and dd elements, respectively.
In other words, if screen readers support these new roles, they should provide announcements appropriate for dl, dt, and dd elements. However, since current screen readers don't support them yet, generic is applied, resulting in the flat reading behavior mentioned earlier.
Purely as an Experiment
Since no screen readers support these new roles yet, this is purely theoretical. We don't know exactly what announcements appropriate for dl, dt, and dd elements will sound like. We can only look forward to future evolutions in screen readers. Since these new roles are still in the draft stage, there's also a possibility they might be removed.
However, through this experiment, I discovered that leveraging the fallback property of the role attribute could allow for graceful degradation of roles. While keeping an eye on the evolution of WAI-ARIA, it might be interesting to experiment with this property.
This experiment is actually implemented on the Accessibility Conference Fukuoka website. If you want to check the behavior yourself, please try browsing it with a screen reader.
Of course, as I've said repeatedly, I am doing this only because I am the owner and markupper of this site, so please do not copy this in actual products or client projects.
Discussion