References

Beginner-friendly references for web development, with live, editable examples.

The HTML <var> tag

Element All modern browsers Updated
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 namex 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> &times; <var>h</var>.</p>

Example

Live example
<p>Solve for <var>x</var>: <var>x</var> + 2 = 5.</p>

Best practices

  • Use <var> for variables and placeholders — equation variables, parameter names, fill-in values.
  • For source-code identifiers in general, prefer <code>.
  • Combine it with <sub>/<sup> for subscripted or exponented variables.
  • Do not use it merely to italicize text — that is a CSS job.

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.