<var>
The <var> element represents a variable in a mathematical expression, programming context, or placeholder text. It is typically rendered in italics by browsers, distinguishing variables from surrounding text and making formulas and code explanations clearer.
This page was last updated on 2025-11-17
Syntax
<var>variable name</var>
The element requires both opening and closing tags. The content is the name of the variable.
Attributes
- Global attributes - The <var> element supports all global attributes such as
id,class,style,lang, anddir.
The <var> element has no element-specific attributes.
Examples
Mathematical Expression
<p>The area of a rectangle is calculated as <var>A</var> = <var>l</var> × <var>w</var>, where <var>l</var> is length and <var>w</var> is width.</p>
Programming Variable
<p>Store the user's name in the <var>userName</var> variable.</p>
Placeholder in Instructions
<p>Replace <var>your-username</var> with your actual GitHub username in the URL.</p>
Combined with Code Element
<p>The function <code>calculate(<var>x</var>, <var>y</var>)</code> returns the sum of the two parameters.</p>
When to Use
Use the <var> element when:
- Writing mathematical formulas or equations
- Documenting programming concepts with variable names
- Creating placeholder text that users should replace
- Explaining algorithms where you reference variable values
- Describing scientific formulas or physical constants
Note: Don't use <var> for all italicized text. Use <em> for emphasis, <i> for alternate voice or technical terms, and <cite> for titles of works. Reserve <var> specifically for variables.