HTML <time>
Tag: Representing Date & Time
The <time>
tag in HTML is used to define dates, times, or durations in a machine-readable format. It helps search engines and browsers understand time-related information better.
1. Basic Syntax
✅ Displays: The event starts on June 15, 2025.
✅ Helps search engines & assistive technologies understand the date.
2. Attributes of <time>
Attribute | Description | Example |
---|---|---|
datetime | Machine-readable date/time format | <time datetime="2025-06-15">June 15, 2025</time> |
3. Examples of <time>
Usage
š Example 1: Full Date with datetime
✅ Search engines recognize March 28, 2024 correctly.
š Example 2: Time Representation
✅ Helps browsers recognize 2:30 PM as a valid time.
š Example 3: Date & Time Combined
✅ Uses ISO 8601 format (YYYY-MM-DDTHH:MM
).
š Example 4: Duration Format
✅ Uses "PT2H30M" (ISO duration format).
✅ Helps search engines and voice assistants understand durations.
4. Styling <time>
with CSS
✅ Makes the date bold & blue.
5. When to Use <time>
✅ Blog posts & news articles: Show publication dates.
✅ Events & schedules: Display event times in machine-readable format.
✅ Durations: Indicate time spans like cooking time, movie length, etc.
6. Conclusion
-
The
<time>
tag improves SEO & accessibility. -
Use
datetime
for machine-readable formatting. -
Helps search engines & voice assistants understand time-related info.