Problem Statement
What is the purpose of the <time> element?
Explanation
The time element represents dates and times in a machine-readable format using the datetime attribute. This helps search engines, calendars, and other tools understand temporal information. The visible text can be formatted for humans, while datetime provides the standard format. For example, time datetime equals 2024 hyphen 01 hyphen 15 shows January 15, 2024 to users but 2024-01-15 to machines. The datetime attribute uses ISO 8601 format. You can represent dates, times, or both. The time element is useful for publication dates, event times, or any temporal data. It improves SEO by helping search engines understand when content was published or events occur. It also helps browsers offer to add events to calendars.
Code Solution
SolutionRead Only
<!-- Publication date -->
<article>
<h2>Article Title</h2>
<p>Published on
<time datetime="2024-01-15">January 15, 2024</time>
</p>
</article>
<!-- Date and time -->
<p>The event starts at
<time datetime="2024-03-20T19:00:00">
7:00 PM on March 20, 2024
</time>
</p>
<!-- Duration -->
<p>The video is
<time datetime="PT2M30S">2 minutes 30 seconds</time> long
</p>
<!-- Relative time -->
<p>Posted
<time datetime="2024-01-15T10:30:00"
title="January 15, 2024 at 10:30 AM">
2 hours ago
</time>
</p>
<!-- Just a year -->
<p>Copyright <time datetime="2024">2024</time></p>Practice Sets
This question appears in the following practice sets:
