The Time Element — HTML

The <time> tag marks a date, a time or a length of time: <time datetime="2026-04-15">15 April 2026</time>. The datetime attribute is for machines (search…

An invite in the family group chat says "next Saturday, 7 pm". You understand it right away. The calendar app on your phone doesn't. It needs an exact date, in a format it can read.

That is what <time> is for. It marks a date, a time or a length of time inside your text. You write the date twice:

Machines here means search engines, calendar apps, or scripts (small programs) that read the page.

One date, two readers

Here is a date inside a paragraph:

<p>Date: <time datetime="2026-04-15">15 April 2026</time></p>

Visitors see only "Date: 15 April 2026". The value 2026-04-15 doesn't show, but machines can read it.

You can change the text to "next Wednesday" or "mid-April", and machines still read 2026-04-15. They read only the datetime attribute, not the text between the tags.

Like other attributes that have a value, datetime is written name="value" inside the opening tag. <time datetime> with no ="..." holds no date at all. A date written as text between <time> and </time> doesn't count as the attribute either.

The format of datetime

Machines can only read a fixed format (called ISO 8601). No month names and no spaces:

Lengths of time

A length of time is written like this:

<p>Length: <time datetime="PT2H30M">2 hours 30 minutes</time></p>

How to read PT2H30M:

So PT45M means 45 minutes, and PT1H means 1 hour. Days come before the T: P3D means 3 days. Be careful: in HTML, an M may only come after the T, and it means minutes. An HTML duration can't contain months or years, because their number of days is not fixed. For a month, write the number of days, such as P30D.

⚠️ Wrong format, wrong place

TL;DR: The <time> tag marks a date, a time or a length of time: <time datetime="2026-04-15">15 April 2026</time>. The datetime attribute is for machines (search engines, calendar apps), the text between the tags is for people. The datetime format is fixed and has no spaces: 2026-04-15 (date), 19:30 (time), 2026-04-15T09:30+07:00 (date, time and time zone), PT2H30M (2 hours 30 minutes). Write the <time> inside its paragraph, not outside it.

⚡ One date, two readers

Write:

<p>Date: <time datetime="2026-04-15">15 April 2026</time></p>
Guess first: if you change the text to "next Wednesday", what date does a calendar app read?

Still 2026-04-15. Machines (calendar apps, search engines) read only the datetime attribute, not the text between the tags.

Meaning: The datetime attribute is for machines, and it doesn't show on the page. The text between the tags is for people, and you can write it any way you like.

⚡ Year first, no spaces

Guess first: can machines read datetime="15-04-2026"?

No. The format has to be year first: 2026-04-15.

Meaning: A date is 2026-04-15, a time 19:30, a date and time 2026-04-15T09:30. The letter T separates the date from the time. Add +07:00 at the end for the time zone UTC plus seven (seven hours ahead of UTC, the world's reference time). Write all of them with no spaces.

⚡ Lengths of time

Write:

<p>Length: <time datetime="PT2H30M">2 hours 30 minutes</time></p>

Meaning: P marks a length of time, T marks where the hours, minutes and seconds start, then H hours, M minutes, S seconds. So PT2H30M means 2 hours 30 minutes. Be careful: an HTML duration can't contain months, so M only comes after the T (minutes).

What you will learn