Definition
A <time>
element represents a specific date, time, or duration. It must adhere to a valid syntax. You can specify a more readable (non-valid syntax) date or time by placing a valid version in an optional datetime
attribute.
Example
<p>The shop opens at <time>22:00</time> pm.</p>
<p>I am going to the movies on <time datetime="2021-03-05 20:00">Friday</time>.</p>
Usage
- Both the opening and closing tags are required.
- The
<time>
element can be used anywhere phrasing content is expected. - If the
<time>
element has adatetime
attribute, its content can be any phrasing content. - If the
<time>
element does not have adatetime
attribute, its content must be a valid date or time string. It also must not contain any element descendants. - For details of valid datetime formats, see below.
Attributes
The <time>
element supports the Global Attributes, as well as the following:
datetime
The
datetime
attribute specifies a machine-readable format of the<time>
element. The value should be both:- A date in the Gregorian Calendar
- A date in the proper format. See below.
Valid datetime
formats
- A valid year string
<time>2021</time>
- A valid month string
<time>2021-02</time>
- A valid date string
<time>2021-02-18</time>
- A valid yearless date string
<time>11-18</time>
- A valid time string
<time>18:23</time> <time>18:23:47</time> <time>18:23:47.929</time>
- A valid local date and time string
<time>2021-02-18T18:23</time> <time>2021-02-18T18:23:47</time> <time>2021-02-18T18:23:47.929</time> <time>2021-02-18 18:23</time> <time>2021-02-18 18:23:47</time> <time>2021-02-18 18:23:47.929</time>
- A valid time-zone offset string
<time>Z</time> <time>+0000</time> <time>+00:00</time> <time>-0800</time> <time>-08:00</time>
- A valid global date and time string
<time>2021-02-18T18:23Z</time> <time>2021-02-18T18:23:47Z</time> <time>2021-02-18T18:23:47.929Z</time> <time>2021-02-18T18:23+0000</time> <time>2021-02-18T18:23:47+0000</time> <time>2021-02-18T18:23:47.929+0000</time> <time>2021-02-18T18:23+00:00</time> <time>2021-02-18T18:23:47+00:00</time> <time>2021-02-18T18:23:47.929+00:00</time> <time>2021-02-18T06:54-0800</time> <time>2021-02-18T06:54:47-0800</time> <time>2021-02-18T06:54:47.929-0800</time> <time>2021-02-18T06:54-08:00</time> <time>2021-02-18T06:54:47-08:00</time> <time>2021-02-18T06:54:47.929-08:00</time> <time>2021-02-18 18:23Z</time> <time>2021-02-18 18:23:47Z</time> <time>2021-02-18 18:23:47.929Z</time> <time>2021-02-18 18:23+0000</time> <time>2021-02-18 18:23:47+0000</time> <time>2021-02-18 18:23:47.929+0000</time> <time>2021-02-18 18:23+00:00</time> <time>2021-02-18 18:23:47+00:00</time> <time>2021-02-18 18:23:47.929+00:00</time> <time>2021-02-18 06:54-0800</time> <time>2021-02-18 06:54:47-0800</time> <time>2021-02-18 06:54:47.929-0800</time> <time>2021-02-18 06:54-08:00</time> <time>2021-02-18 06:54:47-08:00</time> <time>2021-02-18 06:54:47.929-08:00</time>
- A valid week string
<time>2021-W42</time>
- A valid duration string
<time>PT4H18M3S</time> <time>4h 18m 3s</time>
Specification
Browser Support
Desktop
Chrome | Edge | Firefox | IE | Opera | Safari |
---|---|---|---|---|---|
Yes | Yes | Yes | No | Yes | Yes |
Mobile
Android Webview | Chrome Android | Firefox Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |