HTML <var> Tag

The HTML <var> tag represents a variable within the prose of an HTML document.

The HTML5 specification states that this could be an actual variable in a mathematical expression or programming context, an identifier representing a constant, a symbol identifying a physical quantity, a function parameter, or just be a term used as a placeholder in prose..

Syntax

The <var> tag is written as <var></var> with the variable inserted between the start and end tags.

Like this:

Examples

Mathematical Expression

Here we use the <var> tag to mark up variables in a mathematical expression.

Placeholder in Prose

Here, the letter "n" is being used as a variable in prose. We don't know whether the number is say, 10, 20, 30 or any other number, so the letter "n" can be used to represent the number - whatever that may be.

Attributes

Attributes can be added to an HTML element to provide more information about how the element should appear or behave.

The <var> element accepts the following attributes.

AttributeDescription
None 

Global Attributes

The following attributes are standard across all HTML elements. Therefore, you can use these attributes with the <var> tag , as well as with all other HTML tags.

For a full explanation of these attributes, see HTML 5 global attributes.

Event Handlers

Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.

Most event handler content attributes can be used on all HTML elements, but some event handlers have specific rules around when they can be used and which elements they are applicable to.

For more detail, see HTML event handler content attributes.