views:

81

answers:

2

Should we use <label> for every input? , even for submit button and keep hidden thorough css if we don't want to show label.

or no need of label for submit button?

.hide {display:none}

<fieldset>
  <legend>Search</legend>
    <label for="Search">Search...</label>
      <input value="" id="Search" name="Search">
    <label for="Submit" class="hide">Submit</label>
      <input type="submit" value="Go!" name="submit" id="submit">
</fieldset>

or we should use like this (no label for submit)

<fieldset>
  <legend>Search</legend>
    <label for="Search">Search...</label>
      <input value="" id="Search" name="Search">
      <input type="submit" value="Go!" name="submit" >
</fieldset>
+2  A: 

No. Don't use labels for elements which have intrinsic label text (e.g. all kinds of buttons). (Note: Faking a label with the value attribute doesn't count).

See the description section of the WCAG section on the subject.

David Dorward
Thanks for the answer and link.
metal-gear-solid
A: 

From official docs:

The LABEL element may be used to attach information to controls. Each LABEL element is associated with exactly one form control.

http://www.w3.org/TR/html4/interact/forms.html#edef-LABEL

Note the term may be not must be. However, it is always a good idea to use a lable, this turns out to be handy:

  • For accessibility reasons
  • For mobile browsers
Sarfraz
This is not my question.
metal-gear-solid
Actually, this answers your question perfectly.
Neurofluxation
@metal-gear-solid if it doesn't answer your question, perhaps you could provide a little more information why not???
Christian Payne
@Neurofluxation, @Christian Payne - if there was any problem in given info in the question then how David Dorward gave very well and accurate answer.
metal-gear-solid
@Sarfraz - you are right "it is always a good idea to use a `label`, this turns out to be handy" but not for every input. it's mentioned in a link provided in David Dorward's answer. my question not should we use `<label>` or not, my question "Should we use `<label>` for every `<input>`"
metal-gear-solid
@Jitendra: i answered your question: "*Should we use <label> for every <input>*" with Note the term may be not must be. It shouldn't be used for every field. Thanks
Sarfraz