# `<var>`

> The `<var>` HTML element represents a variable in a mathematical expression or programming context.

## What is the `<var>` element used for in HTML?

The element that represents a variable in mathematical expressions or programming contexts. It's typically displayed in italics, which distinguishes it from regular text.

- Topic: Semantics
- Type: tag
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 4+, Safari iOS 3.2+

## Example

Wrong:

```html
<p>
  The area is <i>w</i> times <i>h</i>.
</p>
```

Right:

```html
<p>
  The area is <var>w</var> times <var>h</var>.
</p>
```

`<var>` marks the letters as variables, not just italic text.

## Common mistakes

- Using `<var>` for any italic text.
- Using `<var>` for whole code snippets instead of `<code>`.

## Interview questions

### What is the difference between `<var>` and `<code>`?

`<var>` marks a variable name in prose or math, while `<code>` marks a fragment of computer code.

### Should I use `<var>` or MathML?

Use `<var>` for variables in text and `<math>` for full equations.

## Related cards

- [`<code>`](https://wonderium.dev/html/code.md)
- [`<kbd>`](https://wonderium.dev/html/kbd.md)
- [`<samp>`](https://wonderium.dev/html/samp.md)
- [`<math>`](https://wonderium.dev/html/math.md)

---

- Level: [HTML](https://wonderium.dev/html.md)
- HTML version: https://wonderium.dev/html/var
- Last updated: 2026-11-25
