<var>

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; 
}

示例

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

A simple equation: x = y + 2

The output:

Overriding the default style

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.

CSS

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

HTML

<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.

Result

Specifications

Specification Status Comment
HTML Living Standard
<var>
Living Standard
HTML5
<var>
Recommendation

Browser compatibility

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.

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
varChrome Full support YesEdge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support