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:
- once for people, as plain text,
- once for machines, in the
datetimeattribute, in a fixed format.
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>
<p>Date:is the start of an ordinary paragraph. The<time>goes inside it, in the middle of the sentence, because the date is part of that sentence.<time datetime="2026-04-15">is the opening tag.datetime="2026-04-15"is its attribute, written before the>. This is what machines read.15 April 2026is the text visitors see. You can write it any way you like.</time>closes<time>, then</p>closes the paragraph.
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:
- Date:
2026-04-15. Year first, then month, then day, separated by dashes. Month and day always have two digits. - Time:
19:30, 24-hour clock with a colon. - Date and time:
2026-04-15T09:30. The letterTseparates the date from the time. - With a time zone:
2026-04-15T09:30+07:00.+07:00is the time zone UTC plus seven: seven hours ahead of UTC (the world's reference time). AZat the end instead means the time is in UTC.
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:
- The
Pin front marks a length of time (from period). - The
Tmarks where the hours, minutes and seconds start. - After the
T, each number is followed by its unit:Hhours,Mminutes,Sseconds.
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
- Day-first dates. Machines can't read
15-04-2026or15/04/2026. Always write the year first:2026-04-15. - Spaces inside the value. Machines can't read
2026 - 04 - 15. Write it with no spaces. - A
<time>outside the paragraph. If the date is part of the sentence, write</p>after</time>, not before it.
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).