Dofactory.com
Dofactory.com

HTML <var> Tag

The <var> tag is used to mark a variable.

It's used in a mathematical expressions or in computer code.

By default, variables display in italic.

Example

#

A <var> tag with the letter r representing the radius.

πr^2 is the area of a circle.
&pi;<var>r</var>^2 is the area of a circle.
var = variable

More Examples

The <var> elements a, b, and c are part of Pythagora’s theorem.

The Pythagorean theorem: a2 + b2 = c2
The Pythagorean theorem: 
    <var>a</var><sup>2</sup> + <var>b</var><sup>2</sup> = 
    <var>c</var><sup>2</sup>

Attributes for <var>

The <var> element has no attributes, but it does accept global attributes. The following are commonly used.

Attribute Value Description
id   value Provides the variable with a unique identifier.
class   classnames Assigns one or more classnames to the variable.
style   CSS-values Assigns CSS style values to the variable.

For additional global attributes see our global attributes list.


Phrase tags

Phrase tags highlight the meaning of a small piece of text (i.e. a phrase).

The <var> tag, which specifies a variable, is one of them. But there are several others.

A list of all HTML Phrase tags.

Tag Description
<em> Indicates emphasized text
<strong> Indicates important text
<code> Indicates computer code
<samp> Indicates sample output from a computer program
<kbd> Indicates keyboard input
<var> Indicates a variable

Code Tags

The <var> tag is part of a group of tags that create coding (programming) related features on web pages. This group is referred to as the Code tag group. Together, they allow you to create code-friendly pages.

A list of code tags.

Element Description
<pre> Displays pre-formatted text in fixed-width font -- usually computer code
<code> An element that is used to display computer code
<samp> Displays sample output from a coumputer code
<output> Displays output results of a calculation
<var> Marks its content as a variable
<!--...--> Marks text as comments in the source code. Not visible to users

Browser support

Here is when <var> support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like


Last updated on Sep 30, 2023




Guides