Introduction
The <var>
element is used to represents the name of a variable in a mathematical expression or a programming context. It’s typically presented using an italicized version of the current typeface, although that behavior is browser-dependent.
Here is an example of <var> tag :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>The formula to calculate the area of a circle is <var>π</var>r<sup>2</sup>.</p>
</body>
</html>
Output :
In this example:
- The
<var>
element is used to represent the mathematical symbol “π”, which stands for pi. - The
<sup>
element is used to denote the exponentiation. - Together, they represent the formula for calculating the area of a circle.
The <var>
element is purely semantic, meaning it’s used to convey meaning about the content it contains, rather than having any effect on the appearance or behavior of the text. However, browsers typically render the content of <var>
in italics by default, which is often appropriate for denoting variables in a technical context.
It’s worth noting that while <var>
is primarily used for representing variables, it can also be used to represent placeholders for variable content in a more general sense, not limited to mathematical contexts.