HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Tag: time

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.

Brief Explanation of HTML Tag: time

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:

  • Specific dates, such as birthdays or holidays
  • Times of day, such as opening hours or event start times
  • Relative times, such as "3 days ago" or "next week"

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.

Code Examples in HTML Tags

Here are some examples of how the <time> tag can be used:

Specific Date

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:

Specific Time

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:

Relative Time

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:

References

Activity