HTML5 Tutorial - Input Attr : Required field

Input Attr : Required field

A "Required Field" is a field that must be filled in with value before submission of a form. Required field sometimes known as Mandatory field or Compulsory field.

As of writing, only Opera and Firefox support "Required" attribute of input textbox. Please see table below.

Browsers"Required" Support
IE 10
Firefox 4
Safari 5
Chrome 20
Opera 9

To make a field as required field is fairly simple, you are only required to add a "required" boolean attribute into your input element.

<label for="movie">What is your favorite movie : </label>
<input name="movie" type="text" required />
<input type="submit" value="Submit"/>

The picture below shows us how Firefox and Opera prompt user to fill in value if a "Required field" is left blank upon submission.

How browser prompt input for required field

Below is the demo of "Required field", feel free to test it with your browser.