Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder VS Label for input in HTML5

I'm Making a form with multiple inputs where I need to give lable of form element inside input itself and I'm using like this

An example

enter image description here

<form class="TTWForm">
<input type="email" name="email" required="required" placeholder="Email Address">     
</form>

And above code is Valid in W3C validator for HTML5.

Does Label not require in HTML 5?

If I'm using HTML5 Placeholder to show label inside input is that ok?

Does label still required along with placeholder to make it screen reader compatible?

like image 262
Jitendra Vyas Avatar asked Feb 06 '12 09:02

Jitendra Vyas


People also ask

Is label necessary for input HTML?

An <input> element with a type="button" declaration and a valid value attribute does not need a label associated with it.

Should input fields have placeholder text?

Avoid the Placeholder Attribute This is because many users are confused by placeholders. In particular, people with cognitive disabilities tend to have issues understanding placeholder text because they think it is pre-populated text and will try to submit the form without entering their specific information.

Can we use placeholder in label?

Placeholder Attribute Is Not A Label! The placeholder should only be used as a brief example of the text to be entered. Besides inconsistent support for screen readers, using a placeholder as an input label can create usability problems and issues for those with cognitive impairments...

What can I use instead of placeholder in HTML?

The p element placed between the label and input elements acts as a replacement for a placeholder attribute.


1 Answers

HTML validators will not check accessibility. Valid HTML can still be inaccessible or less than optimal. Labels are still important and HTML5 placeholder is not a replacement for them. See H44: Using label elements to associate text labels with form controls in the WCAG 2 Techniques. If your layout requires that the label not be visible to sighted users, you can always include the label but move it offscreen with negative margins/text-indent.

Update:

Some test result on placeholder and a discussion on the W3 Public HTML mailing list about using placeholder without label.

like image 158
steveax Avatar answered Sep 30 '22 22:09

steveax