Course contentsShow
← Web Development
Lesson 1007 of 2,98218. Accessibility FundamentalsFree lesson

Time Element for Dates and Durations

Master the time element to provide machine-readable dates that assistive tech can format appropriately.

Time Element for Dates and Durations

You'll learn how to mark up dates and times in HTML so assistive technologies can present them in the user's preferred format.

The Problem with Plain Text Dates

When you write "March 15, 2024" or "3/15/24" in your HTML, screen readers read it literally. Different users prefer different formats (MM/DD vs DD/MM), and there's no way for assistive tech to automatically convert it to the user's local conventions.

The <time> Element Solution

The <time> element wraps human-readable dates and durations, providing a machine-readable version via the datetime attribute:

<time datetime="2024-03-15">March 15, 2024</time>

The visible text can be whatever format you like, but the datetime attribute follows a standardized format (ISO 8601) that assistive technologies understand.

Common Patterns

Full date:

<time datetime="2024-03-15">March 15, 2024</time>

Date with time:

<time datetime="2024-03-15T14:30">2:30 PM on March 15</time>

Duration:

Video length: <time datetime="PT2H30M">2 hours 30 minutes</time>

Relative dates:

Posted <time datetime="2024-03-15">yesterday</time>

The "PT" prefix in durations stands for "period of time," and screen readers can announce it naturally.

Why It Matters

Users with cognitive disabilities benefit from consistent date formats. Screen reader users can have dates announced in their preferred style. And automated tools can parse your dates reliably for calendars or reminders.

Key Takeaway: Use the <time> element with the datetime attribute to make dates and durations machine-readable, allowing assistive technologies to format them appropriately for each user.