HTML - attributes - for

revision:


Content

"for" attribute : specifies relationships between elements. syntax some examples


"for" attribute : specifies relationships between elements.

top

It can be used on the <label> and <output> elements.

When used together with the <label> element, the "for attribute" specifies which form element a label is bound to, i.e. to specify an "identifier" to the label element.
When used together with the <output> element, the "for attribute" specifies the relationship between the result of the calculation and the elements used in the calculation.


syntax

top

<label for="element_id">

<output for="element_id">

label: element_id: the id of the element the label is bound to.

output: element_id: specifies the relationship between the result of the calculation and the elements used in the calculation.


some examples

top

Click on one of the text labels to toggle the related radio button:


label for="css">CSS


codes
                    <p class="spec">Click on one of the text labels to toggle the related radio button:</p>
                    <form style="margin-left:5vw;" action="action_page.php">
                        <input type="radio" id="html" name="fav_language" value="HTML">
                        <label for="html">HTML</label><br>
                        <input type="radio" id="css" name="fav_language" value="CSS">
                        <label for="css">CSS</label><br>
                        <input type="radio" id="javascript" name="fav_language" value="JavaScript">
                        <label for="javascript">JavaScript</labsel><br><br>
                        <input type="submit" value="Submit">
                    </form>
                
+ =
codes:
                    <form style="margin-left:5vw;" oninput="x.value=parseInt(a.value)+parseInt(b.value)">
                        <input type="range" id="a" value="50">
                        +<input type="number" id="b" value="25">
                        =<output name="x" for="a b"></output>
                    </form>