The value of the for attribute of the label element must be the ID of a non-hidden form control.
Question
I am using following code into my website and when I scan this on w3 validator it shows following error
“The value of the for attribute of the label element must be the ID of a non-hidden form control.” and my code is following.
<div class="from-group mb-3 mb-4">
<div class="form-floating">
<input type="tel" class="form-control" name="mobile" id="mobile" placeholder="name@example.com">
<label for="labelmobile">Mobile Number</label>
</div>
</div>
Answer
label tag is used for the form’s input fields. You have written the code in a wrong way following is the right way of writing the code.
<div class="from-group mb-3 mb-4">
<div class="form-floating">
<input type="tel" class="form-control" name="mobile" id="mobile" placeholder="name@example.com">
<label for="mobile">Mobile Number</label>
</div>
</div>
