What’s the point of using the HTML5 <time> tag?

Html

Html Problem Overview


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.

Html Solutions


Solution 1 - Html

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.

Solution 2 - Html

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.

Solution 3 - Html

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. :)

Solution 4 - Html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCppLearnerView Question on Stackoverflow
Solution 1 - HtmlJeremy RomanView Answer on Stackoverflow
Solution 2 - HtmlTakView Answer on Stackoverflow
Solution 3 - HtmlAlertyView Answer on Stackoverflow
Solution 4 - HtmlDivya ManianView Answer on Stackoverflow