Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Inline Text

The <var> element

Reference for the HTML <var> element: variables in math expressions, programming and placeholders in commands, how it pairs with <code>, and technical details.

The <var> element marks the name of a variable: a symbol in a math expression, an identifier in a program, or a placeholder the reader should replace with their own value. Browsers show it in italics by default.

HTML
<p>If <var>n</var> is even, then <var>n</var> + 1 is odd.</p>

Try it

Variables and placeholders

In the command example, <var> tells the reader that folder-name is not literal text: they should type their own name in its place.

Attributes

This element has no attributes of its own. It accepts the global attributes.

Usage notes

  • <var> with <code>. Inside <code>, <var> picks out the parts of a snippet that are variable names or placeholders. It does not replace <code> for the snippet as a whole.
  • Placeholders. In installation guides and command references, <var> is a clear way to show "replace this" values such as file names, user names or port numbers.
  • Not for any italic text. Use <i> for terms, foreign phrases and similar text, <em> for stress, and CSS font-style: italic for pure styling.
  • Complex math. For fractions, roots, matrices and other layouts, use MathML; <var> works best for short inline expressions.
  • Accessibility. Screen readers usually read <var> as ordinary text. Make sure the sentence makes clear which words are variables or placeholders.

Technical summary

Content categories Flow content, phrasing content, palpable content
Permitted content Phrasing content
Tag omission None; both the start and end tags are required
Permitted parents Any element that accepts phrasing content
Implicit ARIA role No corresponding role
DOM interface HTMLElement
Default display inline (in italics)

Browser support

Supported in every browser.