HTML <time> Tag

Beginner
7 min read
Updated: Nov 2026
4 examples
Live preview

Definition and Usage

The <time> element represents a specific period in time: a clock time, a Gregorian date (optionally with time and timezone), or a duration.

Use the datetime attribute for a machine-readable value while showing friendly text to readers. That helps search tools, scripts, and features such as “add to calendar.” For other machine values that are not dates, prefer <data>.

Baseline · Widely available.

Not deprecated. Stable across browsers since about October 2017.

Pre-Gregorian dates.

Do not use <time> for dates before the Gregorian calendar — those values are not reliable in this element.

Note.

If you omit datetime, the element must contain only text (no nested elements), and that text must itself be a valid datetime string.

HTML Syntax

syntax.html
<time datetime=" value">readable text</time>

Both start and end tags are required. Content is phrasing content when datetime is present. Common datetime shapes: YYYY-MM-DD, HH:MM, YYYY-MM-DDTHH:MM, PT2H30M.

Attributes

Element-specific attributes on <time> (plus global attributes):

AttributeDescriptionTry it
datetimeMachine-readable date, time, datetime, week, year, or duration (must use a valid format)Try it

Global Attributes

The <time> tag also supports the Global Attributes in HTML.

Live Preview

Switch presets to see a real <time> with different datetime values.

Visible text can be friendly; datetime stays precise for machines.

Sentence

Published on .

datetime="2026-11-03"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Human Date + datetime

Show a friendly date while keeping a precise YYYY-MM-DD value.

HTML
<p>
  The event is on
  <time datetime="2018-07-07">July 7</time>.
</p>
Try It Yourself

How It Works

  1. Write the sentence readers should see.
  2. Wrap the date phrase in <time>.
  3. Set datetime="YYYY-MM-DD" for machines.
  4. Keep human text free-form (“July 7”) without changing the attribute.

Example 2 — Time of Day

Mark a 24-hour clock time with HH:MM.

HTML
<p>
  The concert starts at
  <time datetime="20:00">20:00</time>.
</p>
Try It Yourself

How It Works

  1. Choose a valid time string such as 20:00 or 20:00:00.
  2. Put it in datetime.
  3. Show the same or a localized label as the element text.
  4. Seconds and fractions are optional when you need more precision.

Example 3 — Date and Time Together

Combine date and time in one machine value (optional timezone).

HTML
<p>
  The concert took place on
  <time datetime="2001-05-15T19:00">May 15 at 7:00 p.m.</time>.
</p>
Try It Yourself

How It Works

  1. Start with YYYY-MM-DD.
  2. Add T and the time (19:00).
  3. Optionally append a timezone such as Z or +05:30.
  4. Keep the visible text easy for people to read.

Example 4 — Duration

Express how long something lasts with a duration string.

HTML
<p>
  The set lasts
  <time datetime="PT2H30M">2h 30m</time>.
</p>
Try It Yourself

How It Works

  1. Start with P (period / duration).
  2. Use T before time parts such as hours and minutes.
  3. Write 2H30M for two hours and thirty minutes → PT2H30M.
  4. Show a short label like 2h 30m as the element text.

Edge Cases & Pitfalls

Most time mistakes are invalid datetime strings or using the element for non-temporal values.

format

Use a valid microsyntax

Values like 07/07/2018 or July 7 are fine as visible text, but not as datetime. Prefer 2018-07-07.

empty

No nested elements without datetime

If datetime is missing, the element may only contain text that is itself a valid datetime value.

history

Skip pre-Gregorian dates

Ancient or Julian-calendar dates are outside what <time> is meant to encode reliably.

semantics

Not every number is a time

Product codes, scores, and other machine values belong in <data>, not <time>.

Browser Support

The <time> element is core HTML phrasing content in modern browsers. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<time>

Widely available since about October 2017. Chrome, Firefox, Safari, Edge, and Opera all support the element and the datetime attribute.

96% Global support (approx.)
Google Chrome 62+
Full support
Mozilla Firefox 22+
Full support
Apple Safari 7+
Full support
Microsoft Edge 14+
Full support
Opera 49+
Full support
Samsung Internet 8+
Full support
Internet Explorer —
No support
<time> Widely supported

Bottom line: Safe for modern sites. Always pair friendly text with a valid datetime when the visible label is not already machine-readable.

Key Takeaways

  • Role: <time> marks a date, clock time, or duration.
  • datetime: put the precise value in the attribute; keep readable text for people.
  • Formats: YYYY-MM-DD, HH:MM, …T…, PTnHnM, and related microsyntaxes.
  • Limits: not for pre-Gregorian history; not for non-time machine values.

One line: wrap the date phrase in <time> and set a valid datetime for machines.

Default CSS Settings

Typical user-agent styling for time (usually unstyled beyond inline flow):

default.css
time {
  display: inline;
}

Add your own CSS (weight, color, underline) if you want dates to stand out visually.

Frequently Asked Questions

The time element marks a specific date, time of day, or duration. With a datetime attribute, machines get a precise value while humans still see friendly text.
Strongly recommended when the visible text is not already a valid machine format. If you omit datetime, the element's text content must itself be a valid datetime value and must not contain other elements.
Common ones include YYYY-MM-DD, HH:MM, YYYY-MM-DDTHH:MM with optional timezone, week strings like 2013-W46, and durations such as PT2H30M.
No. Avoid time for dates before the Gregorian calendar because conversion and meaning are unreliable for that period.
Browsers do not restyle it much by default. The value is semantic — useful for search, scripts, and calendar features you build.
No. It is Baseline and widely available across modern browsers.

Next: title

Set the document title shown in browser tabs with the HTML title element.

title tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful