
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML required Attribute
The required attribute of the <input> element is used to set a field which is required to be filled before the form is submitted. If the field set with required attribute is not filled, then on clicking the SUBMIT button, the form won’t submit.
Following is the syntax −
<input required>
Let us now see an example to implement the required attribute of the <input> element. Here, we have set 3 fields as required −
Example
<!DOCTYPE html> <html> <body> <h2>Register</h2> <form action="" method="get"> Id − <input type="text" name="id" placeholder="Enter UserId here..." required><br> Password − <input type="password" name="pwd" placeholder="Enter password here..." required><br> DOB − <input type="date" name="dob" placeholder="Enter date of birth here..."><br> Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..." required><br> Email − <input type="email" name="email" placeholder="Enter email here..."><br><br> <button type="submit" value="Submit">Submit</button> </form> </body> </html>
Output
Let’s say we will click the Submit button without filling any of the 3 fields ID, Password and Telephone, then the form won’t submit. We haven’t filled the field “Telephone” here, therefore an error would be visible that won’t allow us to submit the form −
- Related Articles
- HTML required Attribute
- HTML required Attribute
- HTML required Attribute
- HTML input readonly Attribute
- HTML input value Attribute
- HTML DOM Input FileUpload required Property
- HTML DOM Input Month required Property
- HTML DOM Input Number required Property
- HTML DOM Input Radio required property
- HTML DOM Input Password required property
- HTML DOM Input Checkbox required Property
- HTML DOM Input Date required Property
- HTML DOM Input Datetime required Property
- HTML DOM Input DatetimeLocal required Property
- HTML DOM Input Email required Property

Advertisements