77

I have been going through some tutorials on the <time> tag, but I honestly don't see why we are using it.

For example:

Published <time pubdate datetime="2011-07-03">07/03</time>

If we are going to have a string 07/03 anyway, what is the purpose of using a time tag? It doesn't validate anything.

1
  • Mozilla's documentation states that "If the element does not have a datetime attribute, it must not have any element descendants, and the datetime value is the element's child text content." Commented Aug 25, 2024 at 18:51

4 Answers 4

71

The point of this tag, as with a number of the new "semantic" HTML5 tags, is to make it easier for programs to index your data.

A script can go through and easily find out what the published date is for your blog articles if it sees a <time> tag, without having to parse any of a number of ways this could be represented (for consumption by a human being), which would be a much more complex and error-prone task.

Sign up to request clarification or add additional context in comments.

Comments

53

It's in a machine-readable format, so any script or search engine reading your content can understand the date/time of publication. That way you can format it in a nice way for readers without affecting machine readability. It's covered under microformats which are a good thing.

E.g. <time pubdate datetime="2011-07-03">3 days ago</time> looks nice for humans and computers.

Comments

17

HTML5 time element

When in doubt look at the spec!

The time element represents its contents, along with a machine-readable form of those contents in the datetime attribute. The kind of content is limited to various kinds of dates, times, time-zone offsets, and durations, as described below.

From the HTML5.2 spec on the W3C site: https://www.w3.org/TR/html52/textlevel-semantics.html#the-time-element

Have a look at the site for more info. :)

Comments

3

The time element also has an associated DOM API that can be used. See http://my.opera.com/ODIN/blog/2011/05/31/dom-scripting-and-the-time-element and http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-time-element

1 Comment

nice reference. Didn't read through the whole thing yet, but guess it can help :3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.