- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <var> Tag
HTML Tags
HTML <var> Tag
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 <var> 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+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
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.
