HTML: time

By Xah Lee. Date: . Last updated: .

The time tag is used to represent date, time, date+time, duration.

Example:

<p>Captain's log, <time>2011-07-03</time>.</p>
<p>Captain's log, <time>2011-07-03 12:51:02-07:00</time>.</p>
<p>I had lunch at <time>13:58</time>.</p>

Here's another example, with the optional datetime attribute:

<p>I need this <time datetime="2011-07-03 12:28:57-07:00">now</time>!</p>

The datetime attribute is optional. But if not present, then the time tag's content must use the same fomat used by datetime attribute.

“datetime” Attribute

datetime attribute's value is a machine-readable date/time format.

Examples:

<!-- date only -->
mom's birthday <time datetime="2011-07-03">July 3rd</time>
<!-- date and time -->
meeting at <time datetime="2011-07-03 13:00">1 pm</time>
<!-- full date time -->
conference <time datetime="2011-07-03 12:46:03-07:00">12:46:03 PST</time>

“datetime” Attribute Formats

Examples of valid datetime formats:

The space between {date, time} can also be T. Example: 2011-07-03T13:58

The above are the most commonly needed format. The spec also allow {fraction of second, time zone only, year+week, duration}.

Incorrect Use of Time Tag

<!-- incorrect use of time tag -->

<time>today</time>
<!-- incorrect format -->

<time>July 3</time>
<!-- incorrect format -->

<time>07/03/11</time>
<!-- incorrect format -->

<time>Sun Jul 03 13:20:16 2011</time>
<!-- incorrect format -->

thanks to Manuel Strehl https://twitter.com/m_strehl for correction.

back to HTML5 Tags Complete List

HTML Basics

  1. HTML Basics
  2. HTML5 Tags
  3. Case Sensitivity
  4. Allowed Characters
  5. Charset and Encoding
  6. Self-Closing Tags
  7. Multiple Class Value
  8. HTML Entity List

HTML Table

  1. HTML Table Examples
  2. HTML Table, thead, tbody, tfoot
  3. HTML Table, colgroup, col
  4. Styling HTML Table with CSS
  5. CSS: 3 Columns Page Layout
  6. Pure CSS Table

Misc

  1. Viewport Meta
  2. the Root Element
  3. iframe
  4. video
  5. audio
  6. figure
  7. dl, dt, dd
  8. s strike del
  9. time
  10. meter
  11. progress
  12. q
  13. address
  14. canvas
  15. ruby
  16. HTML5 Custom Data Attribute
  17. Big Tag
  18. Image Maps
  19. Marquee, Scrolling Text
  20. How to Markup Subtitle
  21. Meta Language Tag Obsolete
  22. Browser Auto Refresh

HTML4 Frameset

  1. HTML: Split Windows; Frameset
  2. HTML Nested Frameset
Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials