HTML <select> Tag with the 'required' Attribute

<form id="myForm" action="http://www.htmlcodes.ws/resources/html-forms-action.cfm">	

<select name="Food" required>
<option value=""></option>
<option value ="apples">Apples</option>
<option value ="bananas">Bananas</option>
<option value ="oranges">Oranges</option>
</select>

<button>Submit</button>
</form>

The above example demonstrates usage of the <select> element with the required attribute.

Click Submit without selecting an option from the <select> list. Your browser should prevent the form from being submitted, and it should ask you to make a selection from that form control.

The required attribute specifies that the <select> list is a required option for form submission. In other words, a selection must be made before the form can be submitted to the server.

You can test this in the above example by attempting to submit the form without selecting an option from the <select> list.

Boolean Attribute

The required attribute is a boolean attribute. If it is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either required or required="required").

Possible values:

  • [Empty string]
  • required