I don't know why I keep getting this error while checking my page at http://validator.w3.org/check The error was:
Line 235, Column 84: The for attribute of the label element must refer to a form control.
… <label for="name" style="line-height:24px;">Your Name</label><br>
here is my actual code
<div>
<label for="name" style="line-height:24px;">Your Name</label><br>
<input class="css_form_namefield TooltipIstok " type="text" name="name" value="" style="width: 554px;" maxlength="50" >
</div>
<input type="hidden"> <input type="image"> <input type="month"> <input type="number"> <input type="password">
Explanation: The for property is used to associate a label with a certain form control. The value of the for attribute must match the value of the form control's id attribute. The for property is used to associate a label with a certain form of control.
A <label> is used to create a caption for a form control. The <label> can be associated with a form control either implicitly by placing the control element inside the label element, or explicitly by using the for attribute.
Labeling buttons When using the <input> element to create buttons, the label is set in the value attribute of the element. If the image button ( <input type="image"> ) is used, the label is set in the alt attribute, for example: <input type="image" src="searchbutton.
If you use the for attribute in a label element it has to match the id of an input element in your form.
ie
<label for="field-id" style="line-height:24px;">Your Name</label><br>
<input type="text" id="field-id">
This page may be helpful for more information. http://www.w3.org/TR/WCAG-TECHS/H44.html
By definition, the for
attribute value must match the id
attribute value of “another” form control, to use the HTML 4.01 terminology. Controls are created by input
, textarea
, button
, select
, or object
elements, so just read “another” as “a”. HTML5 puts this somewhat differently, specifying that the attribute must refer to a labelable element.
From the error message, it seems that you are validating against HTML5, so the rule that applies is that the for
attribute must refer to a button
, input
(other than with type=hidden
), keygen
, meter
, output
, progress
, select
, or textarea
element. My guess is that you just forgot the id
attribute, incorrectly assuming that the name
attribute could do its job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With