Horje
HTML required Attribute

Definition and Usage

The required attribute is a boolean attribute.

When present, it specifies that the element must be filled out before submitting the form.


Applies to

The required attribute can be used on the following elements:

Elements Attribute
<input> required
<select> required
<textarea> required

Browser Support

The required attribute has the following browser support for each element:


How to add An HTML form with a required input field - HTML required Attribute

Input Example. Here the input will require any text.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<h1>The input required attribute</h1>

<form action="/action_page.php">
  <label for="username">Username:</label>
  <input type="text" id="username" name="username" required>
  <input type="submit">
</form>

</body>
</html>

Output should be:

How to add An HTML form with a required input field - HTML required Attribute

How to add An HTML form with a required drop-down list - HTML required Attribute

The required attribute specifies that the user is required to select a value before submitting the form.
index.html
Example: HTML
<form action="/action_page.php">
  <label for="cars">Choose a car:</label>
  <select name="cars" id="cars" required>
    <option value="">None</option>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </select>
  <br><br>
  <input type="submit" value="Submit">
</form>

Output should be:

How to add An HTML form with a required drop-down list - HTML required Attribute

How to add A form with a required text area - HTML required Attribute

The textarea required attribute.
index.html
Example: HTML
<form action="/action_page.php">
<textarea rows="4" cols="50" name="comment" required>
</textarea>
<input type="submit">
</form>

Output should be:

How to add A form with a required text area - HTML required Attribute




html required attribute

Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin


Read Article
https://develop.horje.com/learn/1434/reference