<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
<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-DDThh:mm:ss). The text content within the
<time> element represents the human-readable date and time that is displayed to users.
<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
<time> element as needed.
In summary, the
<time> element is used to represent a specific point in time or a duration of time in a web page. By using the
<time> element with the
datetime attribute, you can provide semantic meaning to time-related information and enable proper interpretation and presentation by browsers, search engines, and assistive technologies.