<var>
A variable in a math formula or a program, as well as a placeholder symbol in a command.
- Display
- inline
- Closing tag
- Required
- Permitted content
- Phrasing content
Example
#<p>You calculate a rectangle's area with the formula <var>A</var> = <var>a</var> × <var>b</var>, where <var>a</var> and <var>b</var> are the lengths of the sides.</p>
<p>Create a new project with the command <kbd>npx create-next-app <var>project-name</var></kbd>.</p>Definition and usage
#The <var> element marks a variable: a symbol in a math formula, the name of a value in a program description, or a placeholder the reader is meant to replace with something of their own, such as a project name. Browsers display it in italics.
It’s mainly useful in regular text. When you show a whole snippet of a program, mark it as <code>, without wrapping every variable name in <var>.
For more complex formulas, with fractions or roots, there’s MathML, the <math> element. All major browsers have supported it since 2023.
Syntax
#<var>x</var>Attributes
#This element has no attributes of its own. It supports the global attributes, such as class, id and hidden.
Default CSS
#Most browsers display this element with these default styles:
var {
font-style: italic;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Mark placeholder symbols in commands with
<var>, so it’s clear what needs to be replaced. - Write complex formulas in MathML, not with
<var>,<sub>, and<sup>. - Don’t wrap every name in a code block with
<var>.<code>is enough there.
Related entries
#- <code>A piece of computer code: the name of a variable, function, tag, or file, as well as a short listing.
- <kbd>Input entered by the user: keys, keyboard shortcuts, and commands to type.
- <samp>Sample output from a program: a message, a console response, or error text.
- <sub>Subscript: text lowered and shrunk, for example in chemical formulas.
- <sup>Superscript: text raised and shrunk, for example exponents and footnote numbers.
Spotted a mistake or missing an example? Write to us.