2020-07-27
|~1 min read
|160 words
The <time>
tag is an interesting HTML tag I’d not come across before.
It’s primary use seems to be to facilitate interaction between the browser and the user’s system to access reminders, calendars, etc.
A bit like a <span>
tag, <time>
has no native styling, however, because it’s a distinct tag from what’s around it - it can have its own styles or click handlers.
Since you may not want to show a user the ISO standard date-time string, the <time>
tag allows you to get around that by displaying just what’s inside the tag.
For example:
<p>The event starts tonight at <time>8PM</time>.</p>
This isn’t very helpful - but we could add more clarity by assigning a value to the datetime
attribute.
For example:
<p>The event starts tonight at <time datetime="2020-07-07T20:00">8PM</time>.</p>
While this doesn’t do anything on its own (other than help with search engine optimization), it does enable further features for hooking into calendars, etc.
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!