html tutorial - required Attribute in HTML - html5 - html code - html form



Required attribute in html

Learn html - html tutorial - Required attribute in html - html examples - html programs

  • The required attribute is used to specify the input is required and that should not be blank during the form submission.
  • This is a Boolean attribute.

Syntax for required attribute in HTML:

<element required>

Difference between HTML4.01 and HTML 5:

HTML 4.01:

  • HTML4 does not support the required attribute.

HTML 5:

  • The required attribute is new to HTML5.

Applies to:

Element Attribute
<input> required
<textarea> required
<select> required

Sample coding for required attribute in HTML:

Tryit<!DOCTYPE html>
<html>
    <head>
        <title>Wikitechy required attribute</title>
    </head>
    <body>
        <form>
            <input type="text" name="username" required>
            <input type="submit">
        </form>
    </body>
</html>

Code Explanation for required attribute in HTML:

required Attribute Code Explanation

  1. This required attribute used to specifies that the input should be filled during the form submission.

Sample Output for required attribute in HTML:

required Attribute Output part-1

  1. Click the submit button with the blank textbox.
  2. required Attribute Output part-2 submit the form browser shows warning message

  3. When the user try to submit the form the browser shows the warning message.

Browser Support for required attribute in HTML :

5.0 10.0 4.0 No 9.6

Related Searches to required Attribute in html