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

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:

- This required attribute used to specifies that the input should be filled during the form submission.
Sample Output for required attribute in HTML:

- Click the submit button with the blank textbox.
- 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 |