Tag <time> In HTML

The purpose of this article is to explore Tag time with examples to ensure that the learning objectives are achieved.

The <time> tag in HTML is used to represent a specific date and/or time. It provides semantic meaning to the content, making it easier for machines (such as search engines and screen readers) to understand the information on the page. The <time> tag can be used to display a date and/or time in a human-readable format, and can also include additional attributes to provide more information about the time being represented.

Here is basic example of the time and date:

Example: 

<!DOCTYPE html> <html> <body> <p>Event starts at: <time datetime="2022-06-01T19:00">September 11th, 2023 9:00 PM</time></p> </body> </html>

Here is another example of the <time> tag in action:

Example: 

<!DOCTYPE html> <html> <body> <p>The movie <i>Jurassic Park</i> was released on <time datetime="1993-06-11">June 11th, 1993</time>.</p> </body> </html>

Here is an example of how to use the <time> tag to mark up a specific duration of time:

Example: 

<!DOCTYPE html> <html> <body> <p>The song <i>Stairway to Heaven</i> by Led Zeppelin has a duration of <time datetime="PT8M2S">8 minutes and 2 seconds</time>.</p> </body> </html>

How to style the <time> tag in HTML using CSS:

Example: 

<!DOCTYPE html> <html> <head> <style> #mtime { font-weight: bold; color: maroon; } time::before { content: "Date: "; } </style> </head> <body> <p>I will be available for a meeting on <time id="mtime" datetime="2023-02-01T10:00">June 1st at 8:00 AM</time>.</p> </body> </html>


Tag time Uses

The Tag Time <time> describes a certain time (or datetime).

A datetime attribute is used to convert the time into a machine-readable structure so that browsers can offer date reminders in the user’s calendar and search engines can perform more effective searches.

The <time> tag in HTML can be used for various purposes, including:

  • The <time> tag can be used to display a specific date and/or time in a human-readable format. This can be useful for indicating when an event is happening or when content was published.
  • The datetime attribute of the <time> tag can be used to provide a machine-readable format for the date and/or time being displayed. This can be useful for search engines or other software that may be looking for specific information on the page.
  • The <time> tag can also be used to represent a duration or period of time. This can be useful for indicating how long an event will last or how long a piece of content is.
  • The <time> tag can include additional attributes, such as datetime with a timezone offset, to provide more information about the time being represented.
  • The <time> tag can also be used to provide context for a specific date or time. For example, you could use the <time> tag to indicate the date of a historical event or the time when a particular news story broke.

Attributes

Global

The Tag Time <time> is also compatible with Global Attributes in HTML.

Event

The Tag <time> also accepts Event Attributes in HTML.


Attributes List

AttributeValueOverview
datetimedatetimeProvide a machine-readable form for the <time> element


Browser Compatibility

Below is a list of the earliest browser version that fully accommodated the element.

Element
<time>62.018.022.07.049.0

HTML Tag time Advantages

The <time> tag in HTML has several advantages:

  • By using the <time> tag to represent specific dates and times, you are providing semantic meaning to the content on your page. This makes it easier for search engines and screen readers to understand the information being presented.
  • By providing machine-readable data with the datetime attribute, you are also improving the accessibility of your website. Screen readers and other assistive technologies can use this information to provide a better experience for users with disabilities.
  • The <time> tag can provide a more user-friendly experience by displaying dates and times in a human-readable format. This can make it easier for visitors to understand when events are happening or when content was published.
  • By providing machine-readable data with the datetime attribute, you are also improving the search engine optimization (SEO) of your website. Search engines may use this information to provide more relevant search results to users.
Do leave your reaction below as a form of your experience on this site.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *