HTML time Tag: Representing Dates and Times

html time tag

The HTML time Tag marks time values in a document. Use it to show dates or times that machines and users can read.

Understand the <time> Tag in HTML

The <time> tag shows a date or duration in a way that machines understand. It does not show a clock. It shows a point in time or a time span.

Search engines read the <time> tag better. Devices use it for reminders, calendars, or feeds. It helps screen readers say time info clearly. Browsers do not show it differently.

Here is the syntax:

<time datetime="YYYY-MM-DD">Text visible to users</time>

The tag has one main attribute. The text inside the tag shows a readable format. The datetime attribute holds the machine-readable value.

So, how does the datetime attribute work?

The datetime value must use a strict format. Use full dates or times. Use this structure:

  • Date: YYYY-MM-DD
  • Time: hh:mm:ss
  • DateTime: YYYY-MM-DDThh:mm:ss
  • Duration: PnYnMnDTnHnMnS (ISO 8601)

You must write the value in full. Do not leave out zeros. Use T to split date and time.

Here is a quick example:

<time datetime="2025-12-25">25 December 2025</time>

This shows a date to users. The browser reads it as a time point. Take this one. It shows the time:

<time datetime="14:00">2:00 PM</time>

This shows the time in a readable way. The datetime value keeps the strict format.

Do not use the <time> tag for vague words like “tomorrow” or “soon.” Use it only for exact values. Avoid it in places with no machine-read value.

How to Style the <time> Tag with CSS

The tag looks plain by default. You can style it like any inline element.

For example:

time {
  color: #0055aa;
  font-weight: bold;
  font-style: italic;
}

You can also use custom icons or borders to mark the time visually.

Browser Support and Fallback Tips

Modern browsers support the <time> tag. This includes many browsers. Older versions ignore it but still show the text. To ensure fallback:

  • Wrap readable text inside <time>
  • Never hide text in the datetime value

The tag does not break layout or hide info in unsupported browsers.

Examples

Date and Time for Event Start:

<time datetime="2025-08-20T18:30">August 20 at 6:30 PM</time>

This marks a full date with a time. Use it for event pages or schedules. Devices can extract exact timestamps.

Duration of Video:

<time datetime="PT3M45S">3 minutes 45 seconds</time>

This shows a duration in ISO 8601 format. It works for media files. Machines understand the total time without confusion.

Recurrence Time with Only Time Value:

<time datetime="07:45:00">7:45 AM</time>

This example uses only the time part. Use it for routine tasks or transport schedules.

Publish Date of an Article:

<time datetime="2025-07-19">Published July 19, 2025</time>

This shows the date of publication. Search engines extract the publication date. It helps sort content by age.

Wrapping Up

In this article, you learned what the <time> tag does and how it works. You also saw when to use it and how to write the correct format.

Here is a quick recap:

  • Use <time> for exact dates and times
  • Always add the datetime attribute
  • Style it with CSS like any inline element
  • Support is strong in all modern browsers

FAQs

What does the tag in HTML do?

The <time> tag shows a readable time and links it to a machine-readable format using the datetime attribute.

Can I use the tag without the datetime attribute?

You can, but then machines cannot read the value. Always use the datetime attribute to keep it valid and useful.

How do I write a duration in the tag?

Use ISO 8601 format. Example: <time datetime="PT1H30M">1 hour 30 minutes</time>

Is the tag supported in all browsers?

Yes. Modern browsers support it. Old ones show the text but skip special processing.

Similar Reads

HTML bdi Tag: Control Text Direction in HTML

The HTML bdi tag marks text that has an unknown or mixed direction. It makes sure that this part does…

HTML Compatibility: Old vs New Browsers

HTML code does not always show the same result on every browser. Old browsers follow outdated rules while modern browsers…

HTML base Tag: How to Set a Base URL for Links and Resources

Use the <base> tag in HTML to set a single base URL or target for all relative links and resources…

HTML Header Tag: The Complete Guide with Examples

The header tag defines the top part of a page or a section in HTML. It usually holds a heading…

HTML Deprecated Tags and Modern Alternatives List

HTML tags that no longer work stay in the deprecated list. This article explains them and shows the modern replacements.…

HTML Link Attributes Guide for Beginners

HTML link attributes tell the browser how a link works. They set where the link goes, how it opens, and…

HTML Select Tag: How Combo Box & Option Work with Examples

HTML select tag and option tags let users pick values in a form. You use them to create dropdowns. The…

HTML Syntax for Beginners: How it Works with Examples

HTML syntax shows how tags and attributes go together. It gives browsers the rules to read and display a page.…

HTML Breadcrumb Navigation Guide for Beginners

The breadcrumb in HTML shows a path through a site and marks the place of a page inside it. It…

HTML wbr Tag: Word Break Opportunities

The <wbr> tag in HTML helps the browser decide where it can break a word. It does not force a…

Previous Article

HTML address Tag: Contact Information

Next Article

HTML br Tag: Line Breaks

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.