HTML time Element

HTML <time> Element: Human-Friendly, Machine-Readable Dates

Dates tell a story. Whether you're marking a blog post's publish date, highlighting an event, or counting down to something exciting — time matters. And the <time> element gives your dates and timestamps structure, meaning, and clarity — for both readers and machines.

What Is the <time> Element?

The <time> element is used to represent a specific time, date, or duration in HTML. It makes the content semantically recognizable for search engines, screen readers, and scripts — thanks to the optional datetime attribute that provides a standardized format.

Basic Syntax

<p>Published on <time datetime="2025-05-24">May 24, 2025</time>.</p>
Published on May 24, 2025.

The visible text is friendly for humans. The datetime attribute makes it clear for machines.

Why Use <time>?

  • SEO boost: Search engines use structured time for indexing and ranking
  • Accessibility: Assistive technologies can relay dates/times meaningfully
  • Machine processing: JavaScript, calendars, feeds, and crawlers rely on structured dates

Example: Event Timestamp

<h2>Cherry Festival Begins</h2>
<p>Join us on <time datetime="2025-06-01T10:00">June 1st at 10 AM</time> for the opening ceremony.</p>
Join us on June 1st at 10 AM for the opening ceremony.

This timestamp uses both date and time: 2025-06-01T10:00.

Acceptable datetime Formats

  • YYYY-MM-DD → 2025-05-24
  • YYYY-MM-DDThh:mm → 2025-05-24T14:30
  • hh:mm → 14:30 (for durations or times of day)
  • PTnHnM → PT2H30M (ISO 8601 duration format: 2 hours 30 minutes)

Example: Duration Format

<p>This apple picking tour lasts <time datetime="PT1H30M">1 hour and 30 minutes</time>.</p>
This apple picking tour lasts 1 hour and 30 minutes.

Blog Post Metadata Example

<article>
  <h2>Health Benefits of Bananas</h2>
  <p>Posted on <time datetime="2025-05-20">May 20, 2025</time> by FruitDaily.</p>
</article>

Accessibility Tips

  • Always use datetime for structured support
  • Display friendly text inside the tag for visual users
  • Ensure <time> wraps only the relevant text — not entire paragraphs

Use Case: Future Event Countdown

<p>Next cherry shipment arrives on <time datetime="2025-07-15">July 15th, 2025</time>.</p>
Next cherry shipment arrives on July 15th, 2025.

Summary

The <time> element is your semantic shortcut to clarity and machine-readability. You’ve now learned how to:

  • Use <time> for events, durations, and publish dates
  • Write proper datetime values
  • Improve accessibility and SEO with structured timestamps

Check your understanding 1

What is the purpose of the <time> element in HTML?
Choose one answer. You can try again.

Answer and explanation

To display machine-readable dates or times

The <time> element represents a specific time or date in a machine-readable format, which helps browsers and search engines process temporal data accurately.

Check your understanding 2

The datetime attribute in the <time> element is used to specify a human-readable date format.
Choose one answer. You can try again.

Answer and explanation

False

The datetime attribute must contain a machine-readable date/time string in ISO 8601 format, while the element's content can be more human-friendly.

Check your understanding 3

Choose the option that lists all and only the correct statements.

  1. Marking a publication date in a blog post
  2. Displaying the current time with JavaScript only
  3. Labeling an event date in an event listing
  4. Embedding a countdown timer
Which of the following are valid uses of the <time> element?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 3

The <time> element is suited for marking specific dates/times related to content such as publication dates or event dates. It does not handle dynamic features like timers.

Check your understanding 4

What format should the datetime attribute value follow in the <time> element?
Choose one answer. You can try again.

Answer and explanation

ISO 8601 standard (e.g., 2024-05-24)

The datetime attribute must use the ISO 8601 format for machine-readability, ensuring consistent interpretation across browsers and tools.

Check your understanding 5

Using the <time> element can improve SEO by helping search engines understand date and time information.
Choose one answer. You can try again.

Answer and explanation

True

Search engines can parse dates and times marked with <time>, improving indexing and display of time-related content in search results.

Check your understanding 6

Choose the option that lists all and only the correct statements.

  1. datetime
  2. href
  3. class
  4. style
Which attributes can the <time> element have?
Choose one answer. You can try again.

Answer and explanation

Statements 1 and 3 and 4

The <time> element supports the datetime attribute for the machine-readable value and global attributes like class and style. It does not support href.

What’s Next?

Coming up next: the <mark> element — highlight important text and guide the reader’s eye to what matters most.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: HTML mark Element →