The time element is specifically used to display time-based information with the basic syntax being <time datetime="YYYY-MM-DDThh:mm:ssTZD">
.
Examples
Here are a few of the common ways in which we display time:
<time datetime="2013-04-06T12:32+00:00">2 weeks ago</time>
to - Show Source
<time class="time-start" datetime="2016-01-07T12:30"><span class="sr-only">Monday, January 7 </span>12:30 <span class="time-ampm">AM</span></time> <span class="time-to">to</span>
<time class="time-end" datetime="2016-01-07T13:45"> 1:45 <span class="time-ampm">PM</span></time>
to - Show Source
<time class="time-start" datetime="2016-01-07T5:30"><span class="sr-only">Monday, January 7 </span>5:30</time> <span class="time-to">to</span>
<time class="time-end" datetime="2016-01-07T6:30">6:30 <span class="time-ampm">AM</span></time><br>
to - Show Source
<time class="time-start" datetime="2016-01-07T5:30"><strong><span class="sr-only">Monday, January 7 </span>5:30</strong></time> <span class="time-to">to</span>
<time class="time-end" datetime="2016-01-07T6:30">6:30 <span class="time-ampm">AM</span></time><br>
to - Show Source
<time class="time-start" datetime="2016-01-07T05:30">Wednesday, 5:30 <span class="time-ampm">AM</span></time> <span class="time-to">to</span>
<time class="time-end" datetime="06:30">3:00 <span class="time-ampm">PM</span></time><br>
to - Show Source
<time class="time-start" datetime="2015-06-02">Mon, Jun 2, 2015</time> <span class="time-to">to</span>
<time class="time-end" datetime="2015-08-05">Fri, Aug 5, 2015</time>
Usage
Rules
- When possible, use the
<time>
element with thedatetime
attribute when presenting a date or time so that the meaning of the date or time is clear to human users and machine readable. When machines can read the date or time it‘s useful for scheduling with a user‘s calendar, etc.
Constraints
- The
<time>
element does not display time ranges, only single instances, which is why we use two elements to show a range
Principle
- The
<time>
element is used to present dates and times in a machine readable format
Accessibility
- You’ll notice that visually there’s an en-dash separating time ranges, but in the markup it looks like it should be the word “to.“ This is because screen readers handle special characters differently—and some don’t even read them—making the time difficult to audibly understand. The actual text will be read by screen readers and also be able to be copied/pasted.
- Make sure that if the time element is not positioned directly within date or day context that the date is included within the datetime attribute. For additional accessibility that helps screen readers you can include the date in a
.sr-only
class which can often help with context.
Class Names
time-start Modifier |
Use on the start time to ensure that it wraps as a unit instead of breaking apart the time stamp |
time-to Modifier |
Use on a <span> |
time-end Modifier |
Use on the end time to ensure that it wraps as a unit instead of breaking apart the time stamp |
- Last updated April 9, 2018
- Authorable - Yes
- Core - Time
- HTML time datetime Attribute