EN
HTML - set default value for select element
0 points
In this article, we would like to show you how to set a default value for select
element in HTML.
Quick solution:
xxxxxxxxxx
1
<select>
2
<option value="option-value" selected >Default option</option>
3
</select>
In this section, we present a practical example of how to set a default value for a select
element (select box) using selected
attribute.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<form name="my-form">
5
<label>Select fruit: </label>
6
<select name="my-fruits">
7
<option value="apple" selected >🍎 Apple</option>
8
<option value="banana">🍌 Banana</option>
9
<option value="grape">🍇 Grape</option>
10
</select>
11
</form>
12
</body>
13
</html>