W3docs

HTML <var> Tag

The <var> tag describes variable in a mathematical expression or a programming context. See examples.

The <var> tag describes variable in a mathematical expression or a programming context. Its content is usually presented in an italicized version of the current typeface.

Other elements that are used for describing technical parts of the documents in the contexts in which <var> is generally used include:

  • the <code> tag which defines a piece of computer code,
  • the <samp> tag which defines sample output from a script or computer program,
  • the <kbd> tag which defines keyboard output.

If there is a code where the <var> tag is mistakenly used for stylistic purposes and not for semantic ones, you must use either a <span> with appropriate CSS, or an appropriate semantic tag among the following: <q>, <em>,<i> .

The <var> tag is not deprecated, but you can achieve better effects with CSS.

Syntax

The <var> tag comes in pairs. The content is written between the opening (<var>) and closing (</var>) tags.

Example of the HTML <var> tag:

HTML <var> Tag

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    Example <var>This is a variable</var>
  </body>
</html>

Result

var tag example

Attributes

The <var> tag supports the Global attributes and the Event Attributes.

How to style an HTML <var> Tag

{
    "tag_name": "var"
}

Practice

Practice

Which of the following statements are true about the HTML <var> tag?