HTML time tag for duration
I need to display the duration of a video. Should I use <time>
or only use it to display the time, like in a clock?
Example
Is this HTML5 correct?
<p>Duration: <time>3:30 min</time>.</p>
Or should it <time>
only be used in such a situation?
<p>Good morning. The actual time is: <time>9:45</time></p>.
Docs
MDN contains the following definition:
The HTML element represents either a 24-hour clock or an exact date in the Gregorian calendar (with additional time and time zone information). This element is intended to be used to represent dates and times in a machine-readable format. This can be useful for user agents to suggest any event scheduling for the custom calendar.
However, the definition in the W3C is slightly different and it refers to duration:
Indicates the date or time that the item represents.
Value: Any one of the following:
(...)
valid duration string as defined in the [HTML5] specification
Examples:
PT4H18M3S 4h 18m 3s
So, I'm not sure what I should use <time>
in this situation or not. Any thoughts?
source to share
Yes, you can use an element time
for duration.
But the value must be a valid line length that is not used by "3:30 min".
You can use the attribute datetime
to specify the correct value and store "3:30 min" as the content of the element, for example:
<time datetime="3m 30s">3:30 min</time>
source to share
If the specification allows an element to time
have a duration as a value, it means that it can be used that way. The only limitation I found in the spec is that you cannot specify months or years for a duration - only weeks, days, hours, minutes, and seconds. But that shouldn't be a problem for the length of the video).
source to share