summaryrefslogtreecommitdiff
path: root/devdocs/html/element%2Fvar.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/html/element%2Fvar.html')
-rw-r--r--devdocs/html/element%2Fvar.html115
1 files changed, 115 insertions, 0 deletions
diff --git a/devdocs/html/element%2Fvar.html b/devdocs/html/element%2Fvar.html
new file mode 100644
index 00000000..c1c01bbd
--- /dev/null
+++ b/devdocs/html/element%2Fvar.html
@@ -0,0 +1,115 @@
+<header><h1>&lt;var&gt;: The Variable element</h1></header><div class="section-content"><p>The <code>&lt;var&gt;</code> <a href="../index">HTML</a> element 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.</p></div>
+<h2 id="try_it">Try it</h2>
+<div class="section-content"><iframe class="interactive is-tabbed-shorter-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/var.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe></div>
+<h2 id="attributes">Attributes</h2>
+<div class="section-content"><p>This element only includes the <a href="../global_attributes">global attributes</a>.</p></div>
+<h2 id="usage_notes">Usage notes</h2>
+
+<h3 id="related_elements">Related elements</h3>
+<div class="section-content">
+<p>Other elements that are used in contexts in which <code>&lt;var&gt;</code> is commonly used include:</p> <ul> <li>
+<a href="code"><code>&lt;code&gt;</code></a>: The HTML Code element</li> <li>
+<a href="kbd"><code>&lt;kbd&gt;</code></a>: The HTML Keyboard input element</li> <li>
+<a href="samp"><code>&lt;samp&gt;</code></a>: The HTML Sample Output element</li> </ul> <p>If you encounter code that is mistakenly using <code>&lt;var&gt;</code> for style purposes rather than semantic purposes, you should either use a <a href="span"><code>&lt;span&gt;</code></a> with appropriate CSS or, an appropriate semantic element among the following:</p> <ul> <li><a href="em"><code>&lt;em&gt;</code></a></li> <li><a href="i"><code>&lt;i&gt;</code></a></li> <li><a href="q"><code>&lt;q&gt;</code></a></li> </ul>
+</div>
+<h3 id="default_style">Default style</h3>
+<div class="section-content">
+<p>Most browsers apply <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-style"><code>font-style</code></a> to <code>"italic"</code> when rendering <code>&lt;var&gt;</code>. This can be overridden in CSS, like this:</p> <div class="code-example">
+<p class="example-header"><span class="language-name">css</span></p>
+<pre data-signature="ooDCnAfPzSn74y40bqmjyc49gE3Ng9SrzwFS01bQorU=" data-language="css"><span class="token selector">var</span> <span class="token punctuation">{</span>
+ <span class="token property">font-style</span><span class="token punctuation">:</span> normal<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</pre>
+</div>
+</div>
+<h2 id="examples">Examples</h2>
+
+<h3 id="basic_example">Basic example</h3>
+<div class="section-content">
+<p>Here's a simple example, using <code>&lt;var&gt;</code> to denote variable names in a mathematical equation.</p> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="SPY8TiR6LQslieJgDUA+lAn/aZlX4aH+zNwIAY20Nic=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>A simple equation: <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>var</span><span class="token punctuation">&gt;</span></span>x<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>var</span><span class="token punctuation">&gt;</span></span> = <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>var</span><span class="token punctuation">&gt;</span></span>y<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>var</span><span class="token punctuation">&gt;</span></span> + 2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div> <h4 id="result">Result</h4>
+<div class="code-example" id="sect1">
+
+<iframe class="sample-code-frame" title="Basic example sample" id="frame_basic_example" width="650" height="80" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/var/runner.html?id=basic_example" loading="lazy"></iframe>
+</div>
+</div>
+<h3 id="overriding_the_default_style">Overriding the default style</h3>
+<div class="section-content">
+<p>Using CSS, you can override the default style for the <code>&lt;var&gt;</code> element. In this example, variable names are rendered using bold Courier if it's available, otherwise it falls back to the default monospace font.</p> <h4 id="css">CSS</h4> <div class="code-example">
+<p class="example-header"><span class="language-name">css</span></p>
+<pre data-signature="eMzwureY2MmO3vFSVx7d6aZJFB1YB0AdLWORvivgdd8=" data-language="css"><span class="token selector">var</span> <span class="token punctuation">{</span>
+ <span class="token property">font</span><span class="token punctuation">:</span>
+ bold 15px <span class="token string">"Courier"</span><span class="token punctuation">,</span>
+ <span class="token string">"Courier New"</span><span class="token punctuation">,</span>
+ monospace<span class="token punctuation">;</span>
+<span class="token punctuation">}</span>
+</pre>
+</div> <h4 id="html">HTML</h4> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="RedQ7E9Z7ECjbf9ggcbiAUSJKZSFMtKTwq+CdNFjSAs=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
+ The variables <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>var</span><span class="token punctuation">&gt;</span></span>minSpeed<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>var</span><span class="token punctuation">&gt;</span></span> and <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>var</span><span class="token punctuation">&gt;</span></span>maxSpeed<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>var</span><span class="token punctuation">&gt;</span></span> control the minimum
+ and maximum speed of the apparatus in revolutions per minute (RPM).
+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div> <p>This HTML uses <code>&lt;var&gt;</code> to enclose the names of two variables.</p> <h4 id="result_2">Result</h4>
+<div class="code-example" id="sect2">
+
+<iframe class="sample-code-frame" title="Overriding the default style sample" id="frame_overriding_the_default_style" width="650" height="140" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/var/runner.html?id=overriding_the_default_style" loading="lazy"></iframe>
+</div>
+</div>
+<h2 id="technical_summary">Technical summary</h2>
+<div class="section-content"><figure class="table-container"><div class="_table"><table class="properties"> <tbody> <tr> <th scope="row"><a href="../content_categories">Content categories</a></th> <td> <a href="../content_categories#flow_content">Flow content</a>, <a href="../content_categories#phrasing_content">phrasing content</a>, palpable content. </td> </tr> <tr> <th scope="row">Permitted content</th> <td>
+<a href="../content_categories#phrasing_content">Phrasing content</a>.</td> </tr> <tr> <th scope="row">Tag omission</th> <td>None, both the starting and ending tag are mandatory.</td> </tr> <tr> <th scope="row">Permitted parents</th> <td> Any element that accepts <a href="../content_categories#phrasing_content">phrasing content</a>. </td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td><a href="https://www.w3.org/TR/html-aria/#dfn-no-corresponding-role" target="_blank">No corresponding role</a></td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td>Any</td> </tr> <tr> <th scope="row">DOM interface</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement"><code>HTMLElement</code></a></td> </tr> </tbody> </table></div></figure></div>
+<h2 id="specifications">Specifications</h2>
+<div class="_table"><table class="standard-table">
+<thead><tr><th scope="col">Specification</th></tr></thead>
+<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-var-element">HTML Standard <br><small># the-var-element</small></a></td></tr></tbody>
+</table></div>
+<h2 id="browser_compatibility">Browser compatibility</h2>
+<div class="_table"><table>
+<thead>
+<tr id="bct-browser-type">
+<th></th>
+<th colspan="6">Desktop</th>
+<th colspan="6">Mobile</th>
+</tr>
+<tr id="bct-browsers">
+<th></th>
+<th>Chrome</th>
+<th>Edge</th>
+<th>Firefox</th>
+<th>Internet Explorer</th>
+<th>Opera</th>
+<th>Safari</th>
+<th>WebView Android</th>
+<th>Chrome Android</th>
+<th>Firefox for Android</th>
+<th>Opera Android</th>
+<th>Safari on IOS</th>
+<th>Samsung Internet</th>
+</tr>
+</thead>
+<tbody><tr>
+<th><code>var</code></th>
+<td class="bc-supports-yes">1</td>
+<td class="bc-supports-yes">12</td>
+<td class="bc-supports-yes">1</td>
+<td class="bc-supports-yes">Yes</td>
+<td class="bc-supports-yes">15</td>
+<td class="bc-supports-yes">≤4</td>
+<td class="bc-supports-yes">4.4</td>
+<td class="bc-supports-yes">18</td>
+<td class="bc-supports-yes">4</td>
+<td class="bc-supports-yes">14</td>
+<td class="bc-supports-yes">≤3.2</td>
+<td class="bc-supports-yes">1.0</td>
+</tr></tbody>
+</table></div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2005&ndash;2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
+ <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var</a>
+ </p>
+</div>