HTML <time> Tag

HTML

HTML <time> Tag


The <time> tag is one of the HTML5 elements. It is used to define a human-readable time on a 24-hour clock or a precise date in the Gregorian calendar. The DateTime attribute is used to define the machine-readable format, which allows search engines to produce smarter results and user agents to add reminders to the user’s calendar.

Syntax

The <time> tag comes in pairs. The content must be written between opening (<time>) and closing (</time>) tags.

Example

<!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

time example

Attributes

AttributeValueDescription
datetimeIndicates the time and/or date of the element in the formats described below.
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 signaled 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: Allow setting the spacing between words.
Reactions

Post a Comment

0 Comments

close