Skip to main content

HTML Tags

HTML <var> Tag

Written by Updated HTML <var> Tag exercises

The var tag marks a variable: the x in a maths formula, or a name in programming text that stands for a value. Browsers show it in italics, as maths books do.

It belongs to a small family of tags for technical writing: code for code, kbd for keys, samp for program output, and <var> for variables.

Syntax

html

<var>variable_name</var>

It has no attributes of its own, only the global ones.

Example

html

<!DOCTYPE html>
<html>
<head>
  <title>HTML var Tag Example</title>
</head>
<body>
  <h2>HTML &lt;var&gt; Tag Example</h2>
  <p>The area of a rectangle is <var>length</var> × <var>width</var>.</p>
  <p>In the equation <var>x</var> + <var>y</var> = 10, <var>x</var> and <var>y</var> are variables.</p>
</body>
</html>

"length", "width", "x" and "y" appear in italics, set apart from the rest of the sentence.

Good to know

  • Use <var> in prose about maths or code. Inside a block of real code, wrapping every variable is unnecessary.
  • For full mathematical formulas with fractions and roots, MathML (<math>) is the right tool.
  • It is also used for placeholders the reader should replace, like "Type ping <var>hostname</var>".

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

HTML <var> Tag exercises

Mark a variable

Write this paragraph with count marked as a variable: Set count to zero.

Result

Check your answer to see it here.