HTML input placeholder attribute
Example 1
Two input fields with placeholder text:
<form action="demo-form.php">
<input type="text" name="fname" placeholder="First name"><br>
<input type="text" name="lname" placeholder="Last name"><br>
<input type="submit" value="提交">
</form>
<input type="text" name="fname" placeholder="First name"><br>
<input type="text" name="lname" placeholder="Last name"><br>
<input type="submit" value="提交">
</form>
try it"
placeholder text color can also be specified.
Example 2
With placeholder text color settings:
<form action="demo-form.php">
<input type="text" name="fname" placeholder="First name"><br>
<input type="text" name="lname" placeholder="Last name"><br>
<input type="submit" value="提交">
</form>
<input type="text" name="fname" placeholder="First name"><br>
<input type="text" name="lname" placeholder="Last name"><br>
<input type="submit" value="提交">
</form>
try it"
Browser Support
Internet Explorer 10, Firefox, Opera, Chrome and Safari support the placeholder attribute.
Note: 9 and earlier versions of Internet Explorer does not support the placeholder attribute <input> tag.
Definition and Usage
placeholder attribute specifies the input field may describe the expected value of the short message (for example: a short description of the expected sample value or format).
The prompt will be displayed before the user enters a value in the input field.
Note: placeholder attribute applies to the following input types: text, search, url, tel , email and password.
Differences between HTML 4.01 and HTML5
placeholder attribute is new in HTML5 attributes.
grammar
<input placeholder="text">
Property Value
值 | 描述 |
---|---|
text | 规定可描述输入字段预期值的简短的提示信息。 |
HTML <input> tag