Labeling Form Inputs
Labels (<label>) are essential for linking text labels with form input elements, enhancing accessibility and user-friendliness. It's crucial that the for attribute of the <label> tag matches the id attribute of the associated input element.
Example:
<label for="username">Username:</label>
<input type="text" id="username" />
In the example above:
- When you click the
Username:label, it will automatically focus on the corresponding input field; - The
labelandinputare linked together using theforandidattributes, respectively; - Both
forandidattributes have the same value (username).
Let's make filling in the form easier by adding labels to the inputs from the previous example.
index.html
1. What attribute of the <label> tag is used to associate it with a specific <input> element in a form?
2. What attribute is missing for the input element that needs to be associated with the label element?
Takk for tilbakemeldingene dine!
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Fantastisk!
Completion rate forbedret til 2.86
Labeling Form Inputs
Sveip for å vise menyen
Labels (<label>) are essential for linking text labels with form input elements, enhancing accessibility and user-friendliness. It's crucial that the for attribute of the <label> tag matches the id attribute of the associated input element.
Example:
<label for="username">Username:</label>
<input type="text" id="username" />
In the example above:
- When you click the
Username:label, it will automatically focus on the corresponding input field; - The
labelandinputare linked together using theforandidattributes, respectively; - Both
forandidattributes have the same value (username).
Let's make filling in the form easier by adding labels to the inputs from the previous example.
index.html
1. What attribute of the <label> tag is used to associate it with a specific <input> element in a form?
2. What attribute is missing for the input element that needs to be associated with the label element?
Takk for tilbakemeldingene dine!