<time>

Draft

Definition

The <time> HTML element is used to represent a specific point in time or a duration of time. It provides semantic meaning to the time-related information on a webpage and allows browsers, search engines, and assistive technologies to interpret and present the time information appropriately.

Here’s an example of how to use the <time> element:

<p>Article published on <time datetime="2022-03-15">March 15, 2022</time></p>

In this example, the <time> element is used to indicate the specific point in time when an article was published. The datetime attribute is used to provide the machine-readable format of the date and time in the ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDThh:mm:ss). The text content within the <time> element represents the human-readable date and time that is displayed to users.

The <time> element can also be used to represent a duration of time. For example:

<p>
  Conference duration: <time datetime="PT2H30M">2 hours and 30 minutes</time>
</p>

In this case, the datetime attribute uses the duration format (PTnHnMnS) to represent 2 hours and 30 minutes.

It’s important to provide the datetime attribute with a valid and accessible date or time value to ensure proper interpretation by browsers and assistive technologies. Additionally, you can use CSS or JavaScript to style or manipulate the presentation of the <time> element as needed.