JoannaFalkowska
JoannaFalkowska

Reputation: 3677

HTML5 empty <time> tag for date of publication

I'm confused about HTML5 <time> semantic tag. It seems to me it's for tagging strings such as "today", "last Christmas", "10.10.2010", "2am" etc. to help machines recognize and understand them. All valid examples I could find on HTML5 Doctor and W3C page were like:

<p>I have a date on <time datetime="2008-02-14">Valentines day</time>.</p> 

<p>We open at <time>10:00</time> every morning.</p>



But what if I want to set article publication date (e.g. to help Google robots), but without any string displaying it? Would it be valid to have:

<article><time datetime="..."></time> content </article>

or:

<article><time datetime="..." /> content </article>

or should I do that some other way?

(It seems hilarious to me to have e.g. <time datetime="...">...</time> and CSS display:none for time selector...)

Upvotes: 2

Views: 1332

Answers (1)

Igor Gilyazov
Igor Gilyazov

Reputation: 777

The time element contains the datetime value in machine-readable (the datetime attribute) and human-readable (the text content) formats.

The datetime value of a time element is the value of the element's datetime content attribute, if it has one, or the element's textContent, if it does not.

WHATWG

So if the datetime attribute is absent, the datetime value will be parsed from the text content.

If the datetime attribute is present, you are free to write anything into the text content, or nothing in your case.

Upvotes: 1

Related Questions