The multiple attribute allows users to enter or select more than one value in an input field. It is commonly used with file and email input types.
- Allows selection of multiple files or multiple email addresses.
- Commonly used with <input type="file"> and <input type="email">.
- Improves flexibility by accepting multiple inputs at once.
Syntax:
<input multiple> Example: Multiple attribute to create a form with multiple file input in single input element.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML input multiple Attribute</title>
<style>
h1, h2 {
text-align: center;
color: green;
font-style: italic;
}
form {
text-align: center;
margin-top: 30px;
}
</style>
</head>
<body>
<h1>GeeksForGeeks</h1>
<h2>HTML input multiple Attribute</h2>
<!--Driver Code Ends-->
<form action="">
<label>Select images:</label>
<input type="file" name="img" multiple>
<input type="submit" value="Submit">
</form>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->
- In this example we have Header elements (<h1> and <h2>) styled in green and italicized.
- Includes a form with a file input (<input type="file">) with the multiple attribute allowing selection of multiple files.
- Provides a submit button (<input type="submit">) within the form for user interaction.
HTML <input> multiple Attribute Use cases
- Multiple Value Input: The multiple attribute allows users to enter or select more than one value in an input field.
- Multiple File Selection: When used with <input type="file">, it enables users to select and upload multiple files at the same time.
- HTML5 Support: The multiple attribute is supported in HTML5 and is commonly used for file and email inputs.