diff options
Diffstat (limited to 'devdocs/html/attributes%2Ffor.html')
| -rw-r--r-- | devdocs/html/attributes%2Ffor.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/devdocs/html/attributes%2Ffor.html b/devdocs/html/attributes%2Ffor.html new file mode 100644 index 00000000..b021cd77 --- /dev/null +++ b/devdocs/html/attributes%2Ffor.html @@ -0,0 +1,113 @@ +<header><h1>HTML attribute: for</h1></header><div class="section-content"><p>The <code>for</code> attribute is an allowed attribute for <a href="../element/label"><code><label></code></a> and <a href="../element/output"><code><output></code></a>. When used on a <code><label></code> element it indicates the form element that this label describes. When used on an <code><output></code> element it allows for an explicit relationship between the elements that represent values which are used in the output.</p></div> +<h2 id="usage">Usage</h2> +<div class="section-content"> +<p>When used as an attribute of <code><label></code>, the <code>for</code> attribute has a value which is the <code>id</code> of the form element it relates to.</p> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="k90DFR/sdhD7TkaAGdVvWQdQG3HU2AzS8of0F0qC6Jg=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>label</span> <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>username<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Your name<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>label</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>text<span class="token punctuation">"</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>username<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> <p>When used as an attribute of <code><output></code>, the <code>for</code> attribute has a value which is a space separated list of the <code>id</code> values of the elements which are used to create the output.</p> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="3QYBkr0U2S7ekr01qqTzYcFYMkyK0jMTQAncV7h+xwk=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>range<span class="token punctuation">"</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>b<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>b<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>50<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> + +<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>number<span class="token punctuation">"</span></span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>a<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>a<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>10<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> = +<span class="token tag"><span class="token tag"><span class="token punctuation"><</span>output</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>result<span class="token punctuation">"</span></span> <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>a b<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>60<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>output</span><span class="token punctuation">></span></span> +</pre> +</div> +</div> +<h2 id="examples">Examples</h2> +<div class="section-content"><p>See examples of usage on the element pages for <a href="../element/label"><code><label></code></a> and <a href="../element/output"><code><output></code></a>.</p></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/forms.html#attr-label-for">HTML Standard <br><small># attr-label-for</small></a></td></tr> +<tr><td><a href="https://html.spec.whatwg.org/multipage/form-elements.html#attr-output-for">HTML Standard <br><small># attr-output-for</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>for</code></th> +<td class="bc-supports-yes">10</td> +<td class="bc-supports-yes">≤18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">11</td> +<td class="bc-supports-yes">7</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">11</td> +<td class="bc-supports-yes">7</td> +<td class="bc-supports-yes">1.0</td> +</tr></tbody> +</table></div> +<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>for</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> +<h3 id="html.elements.label.for">html.elements.label.for</h3> +<p>BCD tables only load in the browser<noscript> with JavaScript enabled. Enable JavaScript to view data.</noscript></p> +<h3 id="html.elements.output.for">html.elements.output.for</h3> +<p>BCD tables only load in the browser<noscript> with JavaScript enabled. Enable JavaScript to view data.</noscript></p><div class="_attribution"> + <p class="_attribution-p"> + © 2005–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/Attributes/for" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/for</a> + </p> +</div> |
