HTML <var> Tag for Variables

 

ATTENTION: THIS PAGE IS Valid HTML 5 AND IS BEST VIEWED WITH HTML 5 - Please upgrade your browser or download one of the HTML 5 compatible browsers such as Mozilla Firefox, Chrome, Opera or IE 9 (March 14, 2011 or later). For more information see HTML 5 browsers.


If you find this helpful, please click the Google +1 Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.)


PDF mobile

The <var> Tag in HTML 5

The <var> tag encloses a variable that is to be replaced. It is often used in a block of computer code to indicate . The var element contains the name of the variable and is one of the phrase elements in HTML.

On this site, a variable is styled with a red color and italic font like this: variable. For example (from the definitions of attribute and boolean attribute):

The code for an HTML attribute consists of the attribute name, an equal sign (=) and the value of the property enclosed in quotes.

attribute ="value"

A boolean attribute with a true value is coded with a value that matches the attribute name.

attribute ="attribute"

To indicate a false value the attribute should be completely omitted.

This is an actual working example of the <var> tag example code below.


<var> Tag Syntax

<body>
   ...
   ... phrasing content expected ...<var>... phrasing content ...</var>...
   ...
</body>
Rules for coding the HTML var element

Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.

  1. Code the var element to indicate a variable that is to be replaced where phrasing content is expected.
  2. Begin the var element with a starting <var> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the xmlns attribute on the <html> tag.
  3. Include any HTML global attributes on the <var> tag as appropriate.
  4. Inside the var element, between the starting <var> tag and the ending </var> tag, code the inner HTML phrasing content.
  5. End the var element with a matching </var> closing tag.
Content Model
Content of the var element

The content of the var element can include HTML comments, text content and only those HTML tags that can be used in phrasing content.


<var> Tag Attributes

Attributes of the <var> tag
global attributes The only attributes that can be coded on the <cite> tag are the common HTML attributes.

<var> Tag Examples

Examples of the <var> tag in HTML 5
Example of variables with style
(see <var> tag demo above)
<p>The code for an HTML attribute consists of the
attribute name, an equal sign (<code>=</code>) and
the value of the property enclosed in quotes.</p>

<p style="padding-left: 3em"><var>attribute</var> ="<var>value</var>"</p>

<p>A boolean attribute with a <b>true</b> value is
coded with a value that matches the attribute name.</p>

<p style="padding-left: 3em"><var>attribute</var> ="<var>attribute</var>"</p>

<p>To indicate a <b>false</b> value the attribute should be completely omitted.</p>

Changes in HTML 5 - <var> Tag

What's new in HTML 5
Differences between HTML 5 and earlier versions of HTML

The 2000-2010 Recommendations from the W3C HTML Working Group defined the HTML namespace for the var element type name along with the names of all HTML element types. In older (pre-2000) versions of HTML, element type names were not associated with a namespace.


Valid HTML 5