HTML | required Attribute
It is a Boolean attribute which is used to specify that the input element must be filled out before submitting the Form.
Elements: This attributes can be associated with three elements which are listed below:
- <input>
- <select>
- <textarea>
-
<input>: The required attributes can be use in <input> elements.
- Syntax:
<input required>
- Example-1:
<!DOCTYPE html><html><head><title>required Attribute</title><style>h1, h2 {color:green;font-style:italic;}body {text-align:center;}</style></head><body><h1>GeeksForGeeks</h1><h2>required attribute in input Field</h2><formaction="">Username:<inputtype="text"name="usrname"required><br>Password:<inputtype="password"name="password"><br><inputtype="submit"></form></body></html>chevron_rightfilter_none - Output:

- Syntax:
<select required>
- Example-2:
<!DOCTYPE html><html><head><title>required Attribute</title><style>h1, h2 {color:green;font-style:italic;}body {text-align:center;}</style></head><body><h1>GeeksForGeeks</h1><h2>required attribute in select Field</h2><formaction=""><selectrequired><optionvalue="">None</option><optionvalue="ds">Data Structure</option><optionvalue="algo">Algorithm</option><optionvalue="os">Operating System</option><optionvalue="cn">Computer Network</option></select><inputtype="submit"></form></body></html>chevron_rightfilter_none -
Output:

- Syntax:
<textarea required>
- Example-3:
<!DOCTYPE html><html><head><title>required Attribute</title><style>h1, h2 {color:green;font-style:italic;}body {text-align:center;}</style></head><body><h1>GeeksForGeeks</h1><h2>required attribute in Textarea Field</h2><formaction=""><textarearows="7"cols="50"name="comment"required></textarea><inputtype="submit"></form></body></html>chevron_rightfilter_none - Output:

<select>: This elements can also use required attributes.
<textarea>: This elements can also use required attributes.
Supported Browsers: The browser supported by required attribute are listed below:
- Google Chrome 5.0+
- Internet Explorer 11.0+
- Firefox 4+
- Opera 9.7+
Recommended Posts:
- HTML | <select> required Attribute
- HTML | <textarea> required Attribute
- HTML | <input> required Attribute
- HTML | DOM Input URL required Property
- HTML | DOM Textarea required Property
- HTML | DOM Input Text required Property
- HTML | DOM Input Email required Property
- HTML | DOM Input Checkbox required Property
- HTML | DOM Input Week required Property
- HTML | DOM Input Password required Property
- HTML | DOM Input FileUpload required Property
- HTML | DOM Input Date required Property
- HTML | DOM Input Number required Property
- HTML | DOM Input Radio required Property
- HTML | DOM Input DatetimeLocal required Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



