On a tutorial page you might write a formula like "area = π × radius²", or a code snippet like total = price * quantity. In both cases, some words are not ordinary text: they stand for a value that changes, a radius, a price, a quantity. Nothing in a plain paragraph sets those words apart from the rest of the sentence.
The <var> tag fills that gap: it explicitly marks a word or short expression as a variable, whether inside a maths expression or a code snippet. By default browsers display it in italics, but that style is only a convention, not the point of the tag.
Definition
<var> is a low-level semantic tag that names a variable in a mathematical expression, an identifier in a piece of code, or more generally a placeholder meant to be replaced by an actual value. It computes nothing and declares no variable: it simply describes, for a reader or a tool parsing the page, the nature of that specific word.
You will find it standing alone in an ordinary sentence, or inside a <code> block, to set apart the part that changes, a file name or an identifier to replace, from the fixed syntax around it.
Uses in maths and code
In a formula, <var> wraps each letter standing for a quantity. Writing that the area of a circle equals π times <var>radius</var> squared signals that "radius" is not an everyday word, but an unknown in the formula.
In a code snippet or a technical instruction, it instead marks a placeholder the reader must replace with their own value: "Replace <var>fileName</var> with the actual name of your file". That distinction, between "copy this exactly" and "adapt this part", is precisely what the tag expresses.
Concrete example
Here is a technical instruction combining <code> for the fixed syntax and <var> for the part the reader must customize.
<p>
Run <code>git clone <var>repository-url</var></code> in your terminal.
</p>A reader immediately understands that "git clone" is typed word for word, while "repository-url" is text to replace with the actual repository address.
Not to be confused with JavaScript's var keyword
The name is identical, but the two share nothing else. The var keyword in JavaScript declares an actual variable in a program, with a value that can be read, changed, and used in calculations. The <var> tag in HTML only exists inside the page's text: it stores nothing, runs nothing, and has no existence at all on the program side.
Writing <var>total</var> in an HTML page creates no variable named total accessible from JavaScript, and declaring var total in a script produces no italic text on the page. The confusion comes only from the shared name, inherited from the same English word "variable" used in two completely different contexts: one describes text, the other runs code.
Difference with related tags
<var> belongs to a small family of tags that each describe a different aspect of text related to computer code.
| Tag | What it represents | Typical example |
|---|---|---|
<code> | A code snippet, exactly as it should be written | fetch(url) |
<var> | A variable or a placeholder to replace | url in fetch(url) |
<samp> | Output produced by a program | File not found |
These three tags often combine in the same technical explanation: the fixed code inside <code>, the variable part inside <var>, and the resulting output inside <samp>.
Frequently asked questions
var tag create an actual variable, like in JavaScript?No. It only describes text: it indicates that a word stands for a variable, without storing any value or running any calculation. The browser simply renders it in italics by default, exactly as it would for any other styled text, with no connection to how a JavaScript program actually runs.
var be displayed as something other than italics?Yes, italics is only a default style suggestion, changeable with CSS like any other element, for example with font-style: normal paired with a different color or weight. Changing the appearance changes nothing about the tag's meaning, which stays carried by the HTML, not by the visual style.
var be used for a variable name in a tutorial heading, like "Replace API_KEY with your key"?Yes, that is exactly the intended use. Wrapping "API_KEY" in <var> clearly signals to the reader that this word is a placeholder to replace with their own value, rather than an instruction to copy verbatim, avoiding a common confusion in technical tutorials.