<time>
HTML <time> Tag
The <time> tag is one of the HTML5 elements. It is used to define one of the following:
a human-readable time on a 24-hour clock,
a precise date in the Gregorian calendar (giving optional timezone and time information),
a valid time duration.
The <time> tag should not be used for dates that are prior to the introduction of the Gregorian calendar.
The datetime attribute is used to define machine-readable format, which allows search engines to produce smarter results and user agents to add reminders to the user’s calendar. When the datetime attribute is missing, the <time> element should not have any element descendants. In this case, the datetime value will be the child text content of the element.
Syntax
Syntax
The <time> tag comes in pairs. The content is written between the opening (<time>) and closing (</time>) tags.
Example of the HTML <time> tag:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document.</title>
</head>
<body>
<p>The game will be held on <time datetime="2018-09-28 19:00">September 28</time>.</p>
<p>It will start at <time>19:00</time></p>
</body>
</html>
Result
Attributes
Attributes
Attribute | Value | Description |
---|---|---|
datetime | Indicates the time/date of the element in the following formats: | |
YYYY | - a four-digit year | |
MM | - a two-digit month, 01 - 12 | |
DD | - a two-digit day, 01 - 31 | |
T | -specifies that a time value follows | |
hh | -a two-digit hour, 00 - 24 | |
mm | - a two-digit minute, 00 - 59 | |
ss | -a two-digit second, 00 - 59 | |
TZD | - (Time Zone Designator) time zone |
The <time> tag also supports the Global Attributes.
How to style <time> tag? Common properties to alter the visual weight/emphasis/size of text in <time> tag:
CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit. CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element. CSS font-size property sets the size of the font. CSS font-weight property defines whether the font should be bold or thick. CSS text-transform property controls text case and capitalization. CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style.
Coloring text in <time> tag:
CSS color property describes the color of the text content and text decorations. CSS background-color property sets the background color of an element.
Text layout styles for <time> tag:
CSS text-indent property specifies the indentation of the first line in a text block. CSS text-overflow property specifies how overflowed content that is not displayed should be signalled to the user. CSS white-space property specifies how white-space inside an element is handled. CSS word-break property specifies where the lines should be broken.
Other properties worth looking at for <time> tag:
CSS text-shadow property adds shadow to text. CSS text-align-last property sets the alignment of the last line of the text. CSS line-height property specifies the height of a line. CSS letter-spacing property defines the spaces between letters/characters in a text. CSS word-spacing property sets the spacing between words.