If you find this helpful, please click the Google Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.) |
The <time> Tag in HTML 5
The <time> tag is used to display a time, Gregorian date, or date and time. The time element is one of the phrase elements in HTML.
- Date:
- is the latest in the year Mardi Gras falls until
- Date and time:
- Time only:
These are actual working examples of the <time> tag example code below. Hold the cursor over one of the dates or times to see it in action.
<time> Tag Syntax
<body> ... ... phrasing content expected ...<time datetime="yyyy-mm-ddThr:mi:ss.fracTZ">... phrasing content ... ... phrasing content ...</time>... ... </body>
Rules for coding the HTML time
element
Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.
- Code the time element where phrasing content is expected.
- Begin the time element with a starting <time> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the
xmlns
attribute on the <html> tag. - Include a
datetime
attribute with the date and/or time inyyyy-mm-ddThr:mi:ss.fracTZ
,yyyy-mm-dd
orhr:mi:ss.fracTZ
format. - If the time element is the publication date of the document or of an article element that contains it, include a
pubdate="pubdate"
attribute to indicate that. - Include any other attributes of the <time> tag as appropriate.
- Inside the time element, between the starting
<time>
tag and the ending</time>
tag, code the inner HTML phrasing content with the text version of the time. - End the time element with a matching
</time>
closing tag.
Content Model
Content of the time element
The content of the time element can include HTML comments, text content and only those HTML tags that can be used in phrasing content. It should be the default display format of the date and/or time in the datetime
attribute.
<time> Tag Attributes
Attributes of the <time> tag
global attributes | In addition to the local attributes of the <time> tag below, any of the common HTML attributes can also be coded. |
datetime |
machine-readable date and/or time formatted as datetime="yyyy-mm-ddThr:mi:ss.fracTZ for date and time, datetime="yyyy-mm-dd for date only or datetime="hr:mi:ss.fracTZ for time onlyThe time zone (TZ) can be specified as an offset such as |
pubdate="pubdate" |
<time> Tag Examples
Examples of the time
tag in HTML 5
Date Only
<time xsi:type="xsd:date" datetime="2011-03-08" title="Mardi Gras (Fat Tuesday), 2011">March 8, 2011</time> is the latest in the year Mardi Gras falls until <time xsi:type="xsd:date" datetime="2011-03-09" title="Mardi Gras (Fat Tuesday), 2038" style="cursor: help">March, 2038</time>
Date and Time
<time xsi:type="xsd:dateTime" datetime="2010-12-31T23:59:59-04:00" title="One second before midnight, New Years Eve, 2010" style="cursor: help">12/31/2010 11:59:59 PM EST</time>
Time Only
<time xsi:type="xsd:time" datetime="12:00:00-05:00" title="Noon Eastern time" style="cursor: help">12:00 PM ET</time>
When the cursor hovers over the text for the time element, the cursor: help
style changes the cursor to a question mark to indicate that more information is available. After a brief pause, the text in the title attribute is displayed in a pop-up tool tip. See the <time> tag demos above.
Changes in HTML 5 - <time> Tag
What's new in HTML 5
The <time> tag is one of the new elements in HTML 5.
Differences between HTML 5 and earlier versions of HTML
The <time> tag did not exist in older versions of HTML.
The 2000-2010 Recommendations from the W3C HTML Working Group defined the HTML namespace for the names of all HTML element types, which now includes the time element name. In older (pre-2000) versions of HTML, element type names were not associated with a namespace.