Explanation
The datetime attribute of the <time>
tag specifies a machine-readable date/time. It should follow this format: YYYY-MM-DDThh:mm:ssTZD.
- YYYY: 4-digit year
- MM: 2-digit month (with leading zeros)
- DD: 2-digit day (with leading zeros)
- T: separator
- hh: 24-hour format hour
- mm: minutes (with leading zeros)
- ss: seconds (with leading zeros)
- TZD: Time zone designator (Z or +hh:mm or -hh:mm)
The text within the <time>
tag provides a human-readable date/time and it is displayed to the user if the browser doesn't support the datetime attribute.
Use
The <time>
tag can be used in various scenarios, some of them include:
- Blog posts
- News articles
- Events
- Reviews
- Comments
By using the <time>
tag, search engines and other crawlers can easily recognize a specific date or time on a web page, which can enhance search engine optimization (SEO) and help drive traffic to a website.
Important Points
- The datetime attribute must be in the specified format to be machine-readable.
- The text within the
<time>
tag should be followed by an appropriate date or time format.
- The text within the
<time>
tag is displayed to users if the datetime attribute is not supported by the browser.
- The
<time>
tag can help improve SEO and drive traffic to a website.
Summary
The <time>
tag in HTML is a useful feature that adds semantic value to a webpage by specifying a machine-readable date/time. It enables search engines to recognize the date/time on a webpage, thereby enhancing its SEO value. By using this tag, web developers can easily display dates and times in a consistent format that is both human-readable and machine-readable.