/

HTML / CSS / JavaScript Tutorial

HTML Standard attribute: placeholder

[this page | pdf | back links]

The HTML placeholder attribute indicates the short hint describing the expected value of an <input> or <textarea> element.

 

Valid attribute values (when used with <input> and <textarea> elements) include:

 

Value

Description

text

A short hint that describes what is expected as input

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Set using HTML:<br>
<input type="text" placeholder="hint"><br>

<br><br>Set using JavaScript:<br>
<input id="x1" type="text" >

<script>
var att = document.createAttribute("placeholder");
att.value = "hint";
document.getElementById("x1").setAttributeNode(att);
// or document.getElementById("x1").placeholder = "hint";
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile