I have a simple question about the time element in HTML regarding accessibility. I read this in in the docs according datetime
attribute.
From mdn docs:
The datetime value (the machine-readable value of the datetime) is the
value of the element’s datetime attribute, which must be in the proper
format (see below). If the element does not have a datetime attribute,
it must not have any element descendants, and the datetime value is
the element’s child text content.
From W3 docs:
The datetime attribute of this element is used translate the time into
a machine-readable format so that browsers can offer to add date
reminders through the user’s calendar, and search engines can produce
smarter search results.
This is my time element:
<time>2025-01-20</time>
Question: Is it better according to accessibility best practises and WCAG guidelines to have the datetime
attribute with the same value like this?
<time datetime="2025-01-20">2025-01-20</time>
Clarification:
I want an answer about why and if it would differ according to people with disabilities, accessibility tools (like screen readers etc) or other cases. To have the same value on two places in the same <time>
element or if the datetime
attribute in this case will not make any difference.
1
Yes, it is better according to accessibility best practises and WCAG guidelines to have the datetime attribute with the same value. By doing this so it ensures that the date is both human readable and machine readable and thus enhancing accessibility for readers and others (assistive technologies).
So, your time element is absolutely fine i.e.:
<time datetime="2025-01-20">2025-01-20</time>
I hope now your doubts are resolved.
1