👀 Live Preview
Variables rendered in italic within a sentence:
Let x be the unknown value and n be the sample size.
The formula uses r as the radius.

The <var> tag marks variable names in mathematical and programming content. This guide covers syntax, use cases, comparisons with code, styling, and best practices for beginners.
Wrap variable names in <var> tags.
Mark x, r, and other symbols in formulas.
Highlight identifiers in programming prose.
Variable names vs source code fragments.
Italic defaults and custom highlight classes.
Semantic meaning for assistive technology.
<var> Tag?The <var> element is an inline HTML tag that represents a variable in a mathematical expression or programming context. Browsers typically render it in italics to visually distinguish variable names from surrounding prose.
The HTML <var> element is not the JavaScript var keyword. It marks variable names in educational content—such as x in an equation or count in a tutorial—not executable code.
Use var when you reference a variable by name in text. Use <code> for full source code snippets and <pre> for multi-line blocks.
<p>Substitute <var>n</var> with any positive integer.</p>Enclose the variable name between opening and closing <var> tags:
<var>YourVariable</var><var> is an inline element—it nests inside paragraphs, list items, and table cells.<var />) is not valid in HTML.| Use Case | Code Snippet | Rendered |
|---|---|---|
| Math variable | <var>x</var> | x |
| Formula radius | A = π<var>r</var><sup>2</sup> | A = πr2 |
| Highlighted var | <var class="highlight"> | x |
| In code prose | <code>var <var>name</var></code> | var name |
| Attributes | Global only | class, id, title |
<var> vs <code> vs <em>These inline elements look similar but carry different meanings:
| Element | Purpose | Example |
|---|---|---|
<var> | Variable identifier in math or code prose | radius, x |
<code> | Source code fragment | console.log() |
<em> | Emphasized stress in speech | must, never |
<samp> | Program output sample | Terminal result text |
<kbd> | Keyboard input | Enter |
Browsers default to italic text for var. Customize with CSS classes:
var {
font-style: italic;
}
var.highlight {
color: #1e40af;
background: #eff6ff;
padding: 0.1rem 0.35rem;
border-radius: 4px;
}The <var> tag has no tag-specific attributes. Global attributes and CSS control appearance:
class GlobalCSS hook for highlight colors, backgrounds, and spacing.
class="highlight"title GlobalTooltip explaining what the variable represents.
title="Radius of the circle"<p>The value of <var class="highlight">x</var> in the equation is...</p>Use var for semantic variable names. Do not use it purely for italic decoration—use CSS on span if no semantic meaning applies.
Mathematical formulas, programming references, and styled variable highlights with copy-ready examples and live previews.
Variables rendered in italic within a sentence:
Let x be the unknown value and n be the sample size.
The formula uses r as the radius.
Use <var> in tutorials, documentation, and educational content where variable names need semantic distinction from regular text.
Apply a CSS class to make a variable stand out in mathematical prose.
<p>The value of <var class="highlight">x</var> in the equation is...</p>Mark variables like r in geometry and algebra formulas.
<p>The area of a circle is calculated using the formula A = π<var>r</var><sup>2</sup>.</p>Highlight the variable identifier inside a short code reference within a paragraph.
<p>In the code snippet, <code>var <var>myVariable</var> = 42;</code> initializes a variable.</p>var is used correctly.em for spoken stress, not for variable names.title attribute.pre and code, not only in var.Mark identifiers like x or radius in prose.
Default user-agent styles apply font-style: italic.
Classes add color, background, and spacing for tutorials.
Readers distinguish variable names from ordinary text and code.
The <var> tag is supported in all major browsers. No polyfills are needed.
Every modern browser renders <var> with default italic styling. CSS customization works consistently across platforms.
Bottom line: Use <var> confidently in tutorials and documentation across all browsers.
Mastering the <var> tag helps you convey mathematical and programming concepts clearly. Mark variable names semantically, style them with CSS when needed, and pair with <code> for full source snippets to build accessible, professional technical content.
var for variable identifiers in math and code prosesup and sub in formulascode for full source code fragmentsvar with JavaScript varvarvar only for italic decorationcode blocks with var for snippets<var>Bookmark these before your next coding tutorial.
<var> marks identifiers in math and code prose.
Browsers render var in italics by default.
HTML var is markup, not a JS keyword.
Names in prose vs source code fragments.
ComparisonClasses add color and background for emphasis.
Styling<var> element marks a variable in a mathematical expression or programming context. Browsers typically render it in italics.var marks a variable identifier in prose. code marks a fragment of source code. Use both together when explaining which part of a snippet is the variable name.var is semantic markup for content. JavaScript var is a language keyword inside scripts.var within formulas such as A = πr2.color, background, and padding via CSS classes.var element is fully supported in all modern browsers and Internet Explorer.Practice the <var> tag with math and programming examples in the Try It editor.
5 people found this page helpful