<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
On this page

Example

#
HTML
<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>
Preview

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

#
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:

CSS
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

#

Spotted a mistake or missing an example? Write to us.