The <time>
tag is a semantic tag in HTML that represents a specific time or date. It is used to mark up a date or time in a way that is both machine-readable and human-readable. This tag is useful for web developers who want to provide more context and meaning to their content.
The <time>
tag is used to mark up a specific date or time in a web page. It is a semantic tag, which means that it provides additional meaning to the content. The tag can be used to mark up a variety of different types of dates and times, including:
When using the <time>
tag, it is important to include the date or time in a format that is both machine-readable and human-readable. This can be done using the datetime
attribute, which specifies the date and time in a standardized format. The content of the tag should then be the human-readable version of the date or time.
Here are some examples of how the <time>
tag can be used:
To mark up a specific date, use the <time>
tag with the datetime
attribute set to the ISO 8601 format:
<time datetime="2022-01-01">New Year's Day</time>
This will display as:
To mark up a specific time, use the <time>
tag with the datetime
attribute set to the ISO 8601 format:
<time datetime="T09:00:00-05:00">9:00 AM EST</time>
This will display as:
To mark up a relative time, use the <time>
tag with the datetime
attribute set to the ISO 8601 format and the content set to the human-readable version of the time:
<time datetime="2022-01-01T00:00:00-05:00">New Year's Day</time>
This will display as: