Course contentsShow
← Web Development
Lesson 57 of 2,9822. HTML FundamentalsFree lesson

The <time> Element

Marking dates and times with <time> using the datetime attribute for machine-readable formats.

The <time> Element

You'll learn how to mark dates and times in HTML so both humans and machines can understand them.

What Is the <time> Element?

The <time> element is a semantic HTML tag that identifies dates, times, or durations in your content. While humans can read "January 15, 2024" just fine, machines (like search engines, calendar apps, or screen readers) need a standardized format to process dates reliably. The <time> element bridges this gap by displaying human-friendly text while providing machine-readable data.

How It Works

You wrap dates or times in a <time> tag and use the datetime attribute to provide the machine-readable version:

<p>The concert starts on <time datetime="2024-06-15">June 15, 2024</time>.</p>

The text "June 15, 2024" is what visitors see. The datetime="2024-06-15" follows the ISO 8601 format (YYYY-MM-DD) that computers understand.

Common Uses

Just a date:

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

Date and time:

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

Time only:

<time datetime="14:30">2:30 PM</time>

Why It Matters

Think of <time> like writing a date on a calendar that everyone in the world can read, regardless of their language or date format preference. Search engines can show event dates in search results, browsers can offer to add events to calendars, and assistive technologies can announce dates more clearly.

Key Takeaway: The <time> element makes dates and times understandable to both humans and machines by pairing readable text with the datetime attribute in a standard format.