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

Time and Data Elements

Mark dates and times with <time>, use <data> for machine-readable values.

Time and Data Elements

You'll learn how to mark dates, times, and machine-readable data so computers can understand them as well as humans do.

What Are Time and Data Elements?

When you write "March 15, 2024" or "3:30 PM" on a webpage, humans understand it perfectly. But computers? They need help. The <time> and <data> elements let you provide a machine-readable version alongside your human-friendly text.

Think of it like writing a date on a calendar app: you might type "tomorrow," but the computer stores the actual date internally. These elements work the same way.

The <time> Element

The <time> element marks dates, times, or durations. Use the datetime attribute to provide the computer-readable format:

<p>The concert starts at <time datetime="2024-03-15T19:30">7:30 PM on March 15th</time>.</p>

Between the tags is what people see; inside datetime is what machines read. Browsers, search engines, and assistive technologies can now recognize this as an actual date and time.

The <data> Element

The <data> element connects human-readable content to a machine-readable value using the value attribute:

<p>Product code: <data value="SKU-12345">Wireless Mouse Pro</data></p>

Visitors see "Wireless Mouse Pro," but scripts or systems can access "SKU-12345" programmatically.

Why This Matters

These elements help search engines understand your content better, enable browser features (like adding events to calendars), and improve accessibility for users with assistive technologies.

Key Takeaway: Use <time datetime="..."> for dates and times, and <data value="..."> for any content that needs a machine-readable value behind human-friendly text.