Web Platform Atlas
EN⚡RUUA⚡DE⚡FR⚡ES⚡PL⚡PT⚡ZH⚡JA⚡
Каталог / HTML / The var element

4.5.16 The var element

Статический предпросмотр (RU): для MDN, WPT, глоссария и BYOK-перевода откройте интерактивный Атлас.
⚡ Открыть главу в Атласе

4.5.16 The var element

Категории:

потоковое содержимое.

Фразовое содержимое.

Palpable content.

Контексты, в которых может использоваться этот элемент:

Где ожидается Фразовое содержимое.

Контентная модель:

Фразовое содержимое.

Опущение тегов в text/html:

Ни один из тегов не может быть опущен.

Атрибуты контента:

глобальные атрибуты

Специфика доступности:

Для авторов.

Для разработчиков.

Санитизация:

Default.

DOM-интерфейс:

Uses HTMLElement.

The var element represents a variable. 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.

In the paragraph below, the letter "n" is being used as a variable in prose:

<p>If there are <var>n</var> pipes leading to the ice cream factory then I expect at <em>least</em> <var>n</var> flavors of ice cream to be available for purchase!</p>

For mathematics, in particular for anything beyond the simplest of expressions, MathML is more appropriate. However, the var element can still be used to refer to specific variables that are then mentioned in MathML expressions.

In this example, an equation is shown, with a legend that references the variables in the equation. The expression itself is marked up with MathML, but the variables are mentioned in the figure's legend using var.

<figure> <math> <mi>a</mi> <mo>=</mo> <msqrt> <msup><mi>b</mi><mn>2</mn></msup> <mi>+</mi> <msup><mi>c</mi><mn>2</mn></msup> </msqrt> </math> <figcaption> Using Pythagoras' theorem to solve for the hypotenuse <var>a</var> of a triangle with sides <var>b</var> and <var>c</var> </figcaption> </figure>

Here, the equation describing mass-energy equivalence is used in a sentence, and the var element is used to mark the variables and constants in that equation:

<p>Then she turned to the blackboard and picked up the chalk. After a few moment's thought, she wrote <var>E</var> = <var>m</var> <var>c</var><sup>2</sup>. The teacher looked pleased.</p>