HTML Variable元素(<var>)表示数学表达式或编程上下文中的变量名称。尽管该行为取决于浏览器,但通常使用当前字体的斜体形式显示。


<var> 标签表示变量的名称,或者由用户提供的值。

允许内容 Phrasing content
标签闭合 Both start and end tags are required
允许的父级元素 Any element that accepts phrasing content.
规范元素 HTML, "The var element"


本元素仅支持 全局属性.

DOM 接口

本元素支持 HTMLElement 接口

提示: Gecko 1.9.2 开始, Firefox支持本元素使用 HTMLSpanElement 接口。


var {
  font-style: italic;

Overriding the default style

BCD tables only load in the browser

<p> A simple equation: <var>x</var> = <var>y</var> + 2 </p>

A simple equation: x = y + 2

The output:

Using CSS, you can override the default style for the <var> element. In this example, variable names are rendered using bold Courier if it's available, otherwise it falls back to the default monospace font.


var {
  font: bold 15px "Courier", "Courier New", monospace;


<p>The variables <var>minSpeed</var> and <var>maxSpeed</var> control
   the minimum and maximum speed of the apparatus in revolutions
   per minute (RPM).</p>

This HTML uses <var> to enclose the names of two variables.


Specification Status Comment
HTML Living Standard
Living Standard

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.