Does the select element have the required attribute?
Asked
Active
Viewed 7.4k times
61
-
1Almost dup of http://stackoverflow.com/q/6048710/1178314 which have a more complete answer imo. (Not flagging as dup cause the linked question is doing a false assumption.) – Frédéric Feb 25 '16 at 17:16
5 Answers
150
Yes you can use required attribute in HTML5. But remember, first value should be empty.
<select required>
<option value="">Please select</option>
<option value="first">First</option>
</select>
Here you get the more example:
http://dev.w3.org/html5/spec-author-view/the-select-element.html#the-select-element

Ariful Islam
- 7,639
- 7
- 36
- 54
-
31
-
-
Using Chrome v92 and it still doesn't work without setting `value=""` to `Please select` item – Sumit Wadhwa Aug 25 '21 at 13:53
13
Yes it has a required attribute, you can use it as follows
<select required>
<option value="" disabled selected>Choose</option>
<option value="first Option">First Option</option>
<option value="Second Option">Second Option</option>
</select>
Reference :

Hybris95
- 2,286
- 2
- 16
- 33

Abubakar Ahmed Ruma
- 151
- 1
- 6
1
You can do this way to make it look better
<select required>
<option hidden="" disabled="disabled" selected="selected" value="">Select subject</option>
<option value="first Option">First Option</option>
<option value="Second Option">Second Option</option>
</select>

kamau wairegi
- 428
- 4
- 6
-2
Yes it does, but currently it is not supported by any version of all major browsers. This includes Safari, Chrome, Firefox, and IE.

Idris Armstrong
- 5
- 1
-
That is not true, see [this](http://www.wufoo.com/html5/attributes/09-required.html), for example. This is a very old question which has an accepted answer. – MasterAM Aug 31 '13 at 08:26
-3
It is possible but (just Arif said above) it is important (obviously) that you use the first option without value like:
<form action="#" method="post">
<div>
<label for="State">State</label>
<select required id="State" name="State">
<option value="">Choose</option>
<option value="new">New</option>
<option value="old">Old</option>
</select>
</div>
</form>
You can see more info at: http://www.maxdesign.com.au/2012/11/03/select-required/

juanmjimenezs
- 45
- 3
-
6Welcome to StackOverflow. This looks like it just repeats the information given by the accepted answer. Is there anything you can add to provide more information that would make your answer more distinct? – Jason Baker Oct 31 '14 at 16:13