HTML <var> Tag

Beginner
6 min read
Updated: Nov 2026
4 examples
Live preview

Definition and Usage

The <var> element marks the name of a variable in a mathematical expression or a programming context — for example x in algebra or userId in documentation.

Most browsers render it in italics. For source code snippets use <code>, for keyboard input <kbd>, and for sample program output <samp>. Do not use <var> only to get italic text.

Baseline · Widely available.

Not deprecated. Stable across browsers since about July 2015 (and much earlier in practice).

Not for decoration.

If you only need italics or emphasis, use <em>, <i>, or a <span> with CSS — keep <var> for real variable names.

Not a programming keyword.

In HTML, <var> is an element name. It is unrelated to the var keyword in JavaScript.

HTML Syntax

syntax.html
<var> name</var>

Both start and end tags are required. Content is phrasing content. Place it where phrasing content is allowed (inside a paragraph, sentence, or similar).

Attributes

<var> has no element-specific attributes — only globals. Compare it with related computer-text elements:

ElementDescriptionTry it
<var>Name of a variable (math or programming)Try it
<code>Computer source code or a code fragmentTry it
<kbd>User input (keys or typed commands)See kbd tutorial
<samp>Sample / quoted program outputSee samp tutorial

Global Attributes

The <var> tag also supports the Global Attributes in HTML.

Live Preview

Pick a sentence and see real <var> names rendered (usually italic).

example

Wrap only the variable name — not the whole sentence.

Preview

An algebraic equation: x = y + 2

<var>x</var> and <var>y</var> in an equation

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Algebraic Equation

Mark each variable name in a short equation.

HTML
<p>An algebraic equation: <var>x</var> = <var>y</var> + 2</p>
Try It Yourself

How It Works

  1. Write the equation in a normal paragraph.
  2. Wrap each variable name (x, y) in <var>.
  3. Leave operators and numbers outside the tags.
  4. Browsers typically italicize the variable names.

Example 2 — Programming Variables

Name identifiers in documentation the same way.

HTML
<p>
  The variables <var>minSpeed</var> and <var>maxSpeed</var>
  control the minimum and maximum speed in RPM.
</p>
Try It Yourself

How It Works

  1. Identify the variable names you are talking about in prose.
  2. Wrap only those names in <var>.
  3. Keep the explanation as normal text around them.
  4. Readers can tell which words are identifiers, not ordinary words.

Example 3 — Several Variables in One Formula

Repeat <var> for each named quantity, then define them in the same paragraph.

HTML
<p>
  The volume of a box is
  <var>l</var> × <var>w</var> × <var>h</var>,
  where <var>l</var> is length, <var>w</var> is width,
  and <var>h</var> is height.
</p>
Try It Yourself

How It Works

  1. Mark each letter that stands for a quantity with <var>.
  2. Use the same markup again when you define those letters in words.
  3. Keep symbols like × outside the tags.
  4. Consistency helps screen readers and readers map names to meanings.

Example 4 — var vs code

Use var for the name; use code for a full expression or statement.

HTML
<p>
  Set <var>total</var> with
  <code>total = price * qty</code>.
</p>
Try It Yourself

How It Works

  1. <var> marks the identifier you are talking about.
  2. <code> marks a code fragment (here an assignment).
  3. Default looks differ — italic for var, monospace for code.
  4. Pick by meaning so docs stay clear for both sighted readers and assistive tech.

Edge Cases & Pitfalls

Most var mistakes are using it for italics, wrapping whole sentences, or confusing it with code.

meaning

Do not use var for decoration

Italic-only styling belongs on CSS or on <em> / <i>. Reserve <var> for real variable names.

scope

Wrap the name, not the sentence

Mark x or minSpeed, not an entire explanation. Long spans dilute the meaning of the element.

siblings

Prefer code for full snippets

Statements, filenames, and multi-token expressions usually belong in <code>. Use <var> for the identifier itself.

style

Default italic is optional

Override with CSS (font-style: normal, monospace, bold) when your design needs it. Semantics stay the same.

js

Unrelated to JavaScript var

The HTML element does not declare a JS variable. Teaching pages should say so when beginners might confuse the two.

Browser Support

The <var> element is core HTML in every modern browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<var>

Widely available since about July 2015 (and far earlier in practice). Chrome, Firefox, Safari, Edge, and Opera all support the variable element.

98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer All
Full support
<var> Widely supported

Bottom line: Safe for production docs and tutorials. Mark real variable names, and style with CSS when italic is not enough.

Key Takeaways

  • Role: <var> marks a variable name in math or programming prose.
  • Attributes: globals only — no element-specific attributes.
  • Look: default italic; override with CSS when needed.
  • Siblings: code snippets → <code>; emphasis → <em> / <i>.

One line: wrap only the variable name in <var>, keep styling in CSS, and use <code> for full snippets.

Default CSS Settings

Typical user-agent styling for var (exact values can vary slightly by browser):

default.css
var {
  font-style: italic;
}

Override when needed, for example font-style: normal or a monospace stack for identifier-heavy docs.

Frequently Asked Questions

The var element marks the name of a variable in math or programming — for example x in an equation or minSpeed in docs. It is not a CSS or JavaScript keyword.
No. It only supports the global attributes (id, class, lang, title, and so on).
var names a variable. code marks a fragment of computer code (a statement, filename, or snippet). You can nest them when a variable appears inside code text.
Most browsers set font-style: italic by default. You can override that with CSS when italic is not the look you want.
No. That is presentational misuse. Prefer em for stress emphasis, i for an alternate voice or idiom, or a span with CSS for pure styling.
No. It is Baseline and widely available across modern browsers.

Next: video

Embed video with the HTML video element and media attributes.

video tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful