This template is to help facilitate the displaying of variable names (in mathematics, computer source code, wikimarkup in template documentation, metasyntactic variables, etc.) with the semantically correct<var>...</var> tags, which also renders the variable in italics, as is customary. This method is preferred to simply italicizing for many reasons, including accessibility, separation of presentation and content, semantic Web, and metadata. In XHTML and HTML, the <var> element has semantic meaning, while simple italicization does not. This template provides a tiny hint of kerning to compensate for the italicization and enhance readability.
"Variable" in this sense may include arbitrary or unknown names or terms, examples of human input, arithmetical variables in equations, etc. This template (and the underlying XHTML) are generally not used if MediaWiki's <math>...</math> tags (or any other stand-alone mathematical markup) are being used.
Note that on the screen or in print, this renders as simple italicization, as does ''username'' (using pairs of apostrophes) or <i>username</i> (using HTML), yet it carries more semantic meaning than either of these methods.
At times, you may wish to use a serif font. This is especially true when attempting to render single-letter variables like "I" (upper-case "i") and "l" (lower-case "L"), since they are nearly indistinguishable (if at all). In such situations, use the {{varserif}} template instead of {{var}}, to make them more distinguishable, like these serif examples: Template:Varserif, Template:Varserif.
This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. Click here to see a monthly parameter usage report for this template in articles based on this TemplateData.
TemplateData for Var
Marks text as an HTML variable
Template parameters
Parameter
Description
Type
Status
variable
1
no description
Line
required
class
class
no description
String
optional
ID
id
no description
String
optional
CSS style
style
no description
String
optional
language
lang
no description
Example
c++
String
optional
HTML title (hovertext)
title
no description
String
optional
See also
{{mvar}} which makes the argument italic and formats as mathematics
{{math}} which formats its argument as mathematics
{{bigmath}}, the same as {{math}} but makes it bigger
To indicate text is a variable name. Use for any variable names except those including "I" (uppercase i) and/or "l" (lowercase L); for these, Template:Braces should be used to ensure a noticeable distinction
To display parameters as used in code (i.e. with triple braces), especially to indicate relationships between them. May be combined with Template:Braces above
To display parameter values lightly bordered; replaces <code>...</code>, especially when value contains embedded or leading/trailing blanks; visualized here with middot (·) but can use ␠, ▯, or any character.
To showcase with colors in horizontal format the syntax of any template, while providing an easy way to display placeholder texts using colons as separators
To indicate text is source code. To nest other templates within Template:Braces, use <code>...</code>. {{codett}} differs only in styling: someMethod becomes Template:Codett
To showcase with colors and multiple lines (vertical format) the syntax of any template, while providing an easy way to display placeholder texts using colons as separators