English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: <input> required Attribute

The input required attribute is a boolean attribute. If the required attribute exists, it specifies that the input field must be filled out before submitting the form.

 HTML <input> tag

Online Example

HTML form with a required input field:

<!DOCTYPE html>
<html>
<head>
<title>HTML: <input> required Attribute - Basic Tutorial Website(oldtoolbag.com)</title>
<body>
<form action="action_page.php">
  Username: <input type="text" name="usrname" required>
  <input type="submit">
</form>
</html>
Test to see ‹/›

Browser Compatibility

The numbers in the table indicate the first browser version that supports the attribute.

Attribute




required5.010.04.05.09.6

Definition and Usage

The required attribute is a boolean attribute.

If the required attribute exists, it specifies that the input field must be filled out before submitting the form.

Note:The required attribute applies to the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.

HTML 4.01 with HTML5differences

The required attribute is in HTML5 . New attributes added.

Differences between HTML and XHTML

In XHTML, attribute abbreviations are prohibited, the required attribute must be defined as <input required="required" />.

Syntax

<input required>
 HTML <input> tag