HTML Form
HTML Form
Form elements are the components within an HTML form that allow users to enter
and submit data.
<input> tag is used to create a field where users can enter data, like text,
numbers, or passwords, on a web page
<label> tag in HTML is used to define a caption or name for an input element It
helps users to understand what information they should enter.
<Select> tag in HTML is used to create a dropdown menu where users can choose
one or more options from a list.
<textarea> tag in HTML is used to create a large text box where users can enter
multiple lines of text, like for writing a comment or message.
What are Form Elements ?
<button> tag in HTML creates a clickable button on a web page. When clicked, it
can perform actions like submitting a form or triggering a script.
<fieldset> tag in HTML is used to group related elements, like input fields, within a
form. It helps organize the form and often includes a caption using the <legend> tag.
<legend> tag in HTML is used to provide a title or caption for a <fieldset>. It helps
describe what the grouped form elements are about..
<option> tag in HTML is used to provide the select options in the drop down list .
HTML <input> elements have several attributes that define their behavior and
appearance. Some common attributes include:
name: Defines the name of the input field, which is used when data is submitted.
placeholder: Provides a short hint that describes the expected value of the input.
required: Indicates that the input field must be filled out before submitting the
form.
Attributes of Input Tag.
readonly: Makes the input field non-editable but still allows it to be submitted.
maxlength: Sets the maximum number of characters allowed in the input field.
minlength: Sets the minimum number of characters allowed in the input field.
min and max: Define the minimum and maximum values for number, date, and range
inputs.
pattern: Specifies a regular expression that the input value must match for validation.
autocomplete: Suggests possible input values based on the user's past entries.
autofocus: Automatically focuses on the input field when the page loads.
required: Specifies that an input field must be filled out before submitting the form.
<input type="text" name="username" required>
min and max: Define the minimum and maximum values for numeric, date, or range inputs.
<input type="number" name="age" min="18" max="100">
<input type="date" name="dob" min="1900-01-01" max="2023-12-31">
pattern: Specifies a regular expression that the input value must match for validation.
<input type="text" name="zipcode" pattern="\d{5}">
step: Defines the legal number intervals for numeric input fields.
<input type="number" name="quantity" step="1">
type: Although primarily defining the kind of input, it also has validation purposes, such as
ensuring an email address is correctly formatted
<input type="email" name="email">
autocomplete: Suggests possible input values based on the user's past entries, useful for
ensuring consistent data entry.
<input type="text" name="city" autocomplete="on">