Open In App

HTML <time> Tag

Last Updated : 27 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The <time> tag is used to display the human-readable date/time. It can also be used to encode dates and times in a machine-readable form. The main advantage for users is that they can offer to add birthday reminders or scheduled events to their calendars and search engines can produce smarter search results.

Note: This tag also supports Global Attribute and Event attributes.

Syntax

<time attribute> Time... </time>

Attribute

This tag contains an optional attribute datetime which is used to define the date/time in a machine-readable form of the <time> element.

Example: This example describes the usage of the HTML <time> Tag.

HTML
<!DOCTYPE html>
<html>

<body>
    <h1>GeeksforGeeks</h1>
    <h2>&lt;time&gt; Tag</h2>

    <p>
        I Wake up at <time>6.00</time> 
        in every morning.
    </p>
    <p>
        Jawahar lal Nehru birthday is celebrated 
        on <time datetime="2018--11-14 12:00">
            children's day.</time>
    </p>
</body>

</html>

Output: 

Supported Browsers

HTML <time> Tag – FAQs

What is the purpose of the datetime attribute in the <time> tag?

The datetime attribute stores the date or time in a standardized format (ISO 8601) for better machine readability, even if the displayed format is different.

When should you use the <time> tag?

Use the <time> tag when you want to represent dates, times, or durations that are important to the document’s meaning, such as event dates, publication times, or deadlines.

Is the <time> tag only for displaying exact times?

No, the <time> tag can be used for both exact dates and times as well as durations (e.g., “2 hours”).

Can the <time> tag be used for relative dates like “yesterday”?

Yes, the displayed text can be “yesterday,” but the datetime attribute should contain the exact date for better machine understanding.

Can the <time> tag be used multiple times on a page?

Yes, you can use the <time> tag as often as needed to represent multiple dates, times, or durations in your content.



Next Article

Similar Reads

three90RightbarBannerImg