M4ngo Ranger
M4ngo Ranger

Reputation: 9

How to get placeholder on input (text) to be valid in W3C validator?

Have this code in my HTML

<input name="Username" type="text" placeholder="Username" />
<input name="Password" type="text" placeholder="Password"/>
<input name="Button1" type="button" value="login" />

It works fine when I run it but for my assignment to get good marks, I have to use W3C validator. Is there anyway I can bypass that or fix?

Upvotes: 0

Views: 771

Answers (2)

unor
unor

Reputation: 96707

You can’t use a placeholder attribute in XHTML 1.0.

The placeholder attribute was introduced with (X)HTML5. So if you want to use placeholder, you have to switch to (X)HTML5.

HTML5 document that contains your snippet:

<!DOCTYPE html>
<title>Test</title>

<input name="Username" type="text" placeholder="Username" />
<input name="Password" type="text" placeholder="Password"/>
<input name="Button1" type="button" value="login" />

You can check it with https://validator.w3.org/nu/.

Upvotes: 0

Ian Devlin
Ian Devlin

Reputation: 18880

If you are trying to use placeholder text as a replacement for a label, then no, there is no way around it and this is a good thing because placeholder text is not meant to replace a label but to act as a helpful guide.

Add a label.

Upvotes: 2

Related Questions