GP HTML Input Label
GP HTML Input Label
Input Tag
The <input> tag specifies an input field where the user can enter data. <input>
elements are used within a <form> element to declare input controls that allow users to
input data.
type Attribute
HTML provides different types of input that you can use for different kinds of entries. By
default, the value of type is text, which specifies that we want single-line text input.
● submit
● email
● password
● date
● number
● range
● URL
● checkbox
● radio
● hidden
● time
Browser :
1
value Attribute
Value is not a compulsory attribute to add to the input element.
The value attribute is used differently for different input types:
● For "button", "reset", and "submit" : It defines the text on the button
● For "text", "password", and "hidden" : It defines the initial (default) value of the
input field
● For "checkbox", "radio", "image" - it defines the value associated with the input (It
is also the value that is sent on submit)
Browser :
name Attribute
The HTML form data is sent to the browser or server-side in the form of (name: value),
where value is the entry you provide respective to that name parameter.
The name attribute is a compulsory attribute for input tag in a form.
Without this attribute, this form element won't be submitted or, in other words would
not be sent to the server.
The name attribute also uniquely identifies that piece of data. The value of the input is
accessed using the name attribute.
label Tag
A label tag describes the kind of input in a form, and it is not compulsory. You can do
that without the use of a label tag. But it is better to use the <label> tag to describe the
kind of input for the form element.
2
Example : <label for="fname">First name:</label><br/>
<input type="text" id="fname" name="firstname" />
❖ The label is tied to this input element by giving the "id" attribute of the input
element the same value as the label's "for" attribute.
NOTE : The value of id and name can be the same, and most of the time, this will be the
case.
required Attribute
It specifies that an input field must be filled out before submitting the form. Else, it
shows a pop up to fill out the required field, or you can say it defines a mandatory
field.
The required attribute is a boolean attribute.
Example : <form>
<input type="text" required>
<input type="submit" value="Submit" />
</form>
If we click submit without entering any value, this pop-up shows up.
placeholder Attribute
The placeholder attribute is used with the input element. It describes a sample value or
a short description of the expected format.
The value of the placeholder attribute specifies a short hint that describes the expected
value of an input field.
3
Browser :
Example : <form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>
Browser :
Example : <form>
<label for="dob">Enter DOB : </label>
<input type="date" id="dob" name="dob">
</form>
Browser :
4
Example : <form>
<label for="val"> Value </label>
<input type="range" id="val" name="val" min="0" max="50">
</form>
Browser :
There is also an attribute named checked, that when present, makes the checkbox
selected by default when the page loads.
Example :
<form>
<input type="checkbox" name="color1" value="red"> Red <br>
<input type="checkbox" name="color2" value="green"> Green <br>
<input type="checkbox" name="color3" value="white" checked> White
</form>
Browser :
Example :
<form >
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
5
Browser :
A hidden field often stores what database record needs to be updated when the form is
submitted.
Example : <form>
<label for="Name">Name:</label>
<input type="text" id="Nname" name="Nname"><br><br>
<input type="hidden" id="loc" name="loc" value="India">
<input type="submit" value="Submit">
</form>
Browser :