EN
HTML - create select element placeholder
0 points
In this article, we would like to show you how to create a select element placeholder in HTML.
Quick solution:
xxxxxxxxxx
1
<select>
2
<option selected disabled>Placeholder text...</option>
3
<option value="option-value">option 1</option>
4
</select>
In this section, we present how to create a select box placeholder using selected
and disabled
attributes of an option
element at once.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<form name="my-form">
5
<select name="my-fruits">
6
<option selected disabled>Select fruit</option>
7
<option value="apple" >🍎 Apple</option>
8
<option value="banana">🍌 Banana</option>
9
<option value="grape">🍇 Grape</option>
10
</select>
11
</form>
12
</body>
13
</html>
Note:
The placeholder's text will be visible until the user selects one of the options, then it can't be set back.