HTML Input Attributes
value Attribute
The value attribute specifies the initial value for an input field:
Example
<form action="">
First name:<br>
<input type="text" name="firstname" value="John">
</form>
First name:<br>
<input type="text" name="firstname" value="John">
</form>
This is the manner by which the HTML code above will be displayed in a browser:
Form Attribute
Example
<form action="/action_page.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
Last name: <input type="text" name="lname" form="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
Last name: <input type="text" name="lname" form="form1">
This is the manner by which the HTML code above will be displayed in a browser:
Formaction Attribute
Example
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formaction="/action_page2.php"
value="Submit as admin">
</form>
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit"><br>
<input type="submit" formaction="/action_page2.php"
value="Submit as admin">
</form>
This is the manner by which the HTML code above will be displayed in a browser:
Min and max Attributes
Example
Enter a date before 1980-01-01:
<input type="date" name="bday" max="1979-12-31">
Enter a date after 2000-01-01:
<input type="date" name="bday" min="2000-01-02">
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
<input type="date" name="bday" max="1979-12-31">
Enter a date after 2000-01-01:
<input type="date" name="bday" min="2000-01-02">
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
This is the manner by which the HTML code above will be displayed in a browser:
Multiple Attribute
Example
Select images: <input type="file" name="img" multiple>
This is the manner by which the HTML code above will be displayed in a browser:
Pattern Attribute
Example
Country code: <input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">
This is the manner by which the HTML code above will be displayed in a browser:
Placeholder Attribute
Example
<input type="text" name="fname" placeholder="First name">
This is the manner by which the HTML code above will be displayed in a browser:
Required Attribute
Example
Username: <input type="text" name="usrname" required>
This is the manner by which the HTML code above will be displayed in a browser:
Step Attribute
Example
<input type="number" name="points" step="3">
0 comments:
Post a Comment