The time Element
The time element represents a date/time. It can be in a large number of formats:
<time>2016</time>
represents the year 2016 <time>2016-02</time>
represents February 2016 <time>08:05</time>
represents 5 past 8 in the morning. <time>2016-04-16T18:34:08.240</time>
represents 16th of April 2016 at 6:34 pm and 8.24 seconds.
Since this doesn't have a time zone, it represents the given time in each time zone.
whereas:
<time>2016-04-16T18:34:08.240-0800</time>
represents the same date but only for one timezone, and is therefore a globally unique event.
The time
attribute also has a datetime
attribute. If it is populated, it must contain a machine readable representation of the time
elements content.
The machine readable representation in the examples above would be the values I have placed in the time element. But I can also do this:
<time datetime="2016-12-25">Christmas 2016<time>
which is perfectly valid.
As long as the datetime
attribute is included, then the value of the time element does not have to stick to the formats prescribed above. However, it should still represent a date/time in some form.
The data Element
The data element represents a piece of data and must contain a machine readable form of the data.
This is done by including the value attribute on the data
element.
<data ID="NumberOfPeople" value="144">12 Dozen Men</data>
In the example above, the value of the data is 144
which is 12 * 12
. (A dozen is 12 things)
This data can be used within scripts, etc.
The data
attribute should be used when you want to display the text as well as it having a data
value, but the data-*
attributes that are global to all elements could also be used.
The mark Element
The mark element represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context.
It can be used in two ways.
Either to highlight part of a document in a way that the author didn't originally intend. Such as to bring attention to specific parts of it.
Or to highlight parts of a document to imply something is more relevant to the users' current activity.
The code Element
The code element represents a fragment of computer code.
It can be a fragment of any length, so using it for a variable name is still perfectly valid.
An example would be:
<p>All C# programs start with a <code>main</code> method</p>
You can also write out larger pieces of code such as
<code class="language-CSharp">
public void main()
{
Console.Writeline("Hello World");
}
</code>
As you can see from the code sample above, I have included a class
on the code
element.
The HTML 5 Specification recommends that you indicate the language used within the code
element with a class that is prefixed with "language-
"
The code
element is often also linked with the pre
element which represents pre-formatted text (such as computer code).
The var Element
The var element represents a variable. This can be used in a variety of contexts such as maths, physics and programming code.
The var
element can be used in plain text such as:
<p>In the below sample you will see that the <var>count</var>
variable is used as a counter for the loop.</p>
or within a code
fragment:
<code>
foreach (var <var>item</var> in list)
{
<var>item</var>.DoAction();
}
</code>
Feel free to share your experiences and opinions related to this post in the comments and if you liked this blog post and can't wait to read more, bookmark this site or subscribe to the RSS Feed.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.