The HTML <var> tag
Quick answer
The HTML <var> element represents a variable — in a mathematical expression, a programming identifier, or a placeholder for a value to be substituted. It is rendered italic by default.
Overview
The <var> element marks a variable or placeholder name — x and y in an equation, a parameter name in documentation, or a fill-in-the-blank value such as "rename filename.txt". Browsers italicize it by default.
It is meant for variables in a mathematical or programming sense, not for code in general. For source-code identifiers and expressions, <code> is usually the more appropriate choice; reach for <var> specifically when the text represents a variable standing in for a value.
Syntax
<p>The area is <var>w</var> × <var>h</var>.</p>
Example
<p>Solve for <var>x</var>: <var>x</var> + 2 = 5.</p>
Best practices
Frequently asked questions
What is the var element for?
To mark a variable or placeholder in a mathematical or programming context — like a variable in an equation or a parameter name.
What is the difference between var and code?
<var> represents a variable standing in for a value; <code> is for source code in general.Does var italicize text?
Yes, browsers italicize it by default. Its purpose is semantic, though — restyle it with CSS if needed.
Can I use var for math variables?
Yes — that is one of its intended uses. For complex equations, consider MathML or the <math> element.