Practcal HTML Notes o Level PDF
Practcal HTML Notes o Level PDF
Forms contain special elements called controls like inputbox, checkboxes, radio-buttons, submit
buttons, etc. Users generally complete a form by modifying its controls e.g. entering text, selecting
items, etc. and submitting this form to a web server for processing.
The <form> tag is used to create an HTML form. Here's a simple example of a login form:
Example
Try this code »
1. <form>
2. <fieldset>
3. <legend>Log In</legend>
4. <label>Username: <input type="text"></label>
5. <label>Password: <input type="password"></label>
6. <input type="submit" value="Submit">
7. </fieldset>
8. </form>
The following section describes different types of controls that you can use in your form.
Input Element
This is the most commonly used element within HTML forms.
It allows you to specify various types of user input fields, depending on the type attribute. An
input element can be of type text field, checkbox, password field, radio button, submit button, reset
button, etc. and several new input types introduced in HTML5.
Text Fields
Text fields are one line areas that allow the user to input text.
Single-line text input controls are created using an <input> element, whose type attribute has a
value of text. Here's an example of a single-line text input used to take username:
Example
Try this code »
1. <form>
Note: The <label> tag to define labels for <input> elements. If you want your user to enter
several lines you should use a <textarea> instead.
Password Field
Password fields are similar to text fields. The only difference is; characters in a password field are
masked i.e. shown as asterisks or dots. This is to prevent others from reading the password on the
screen. This is also a single-line text input controls created using an <input> element
whose typeattribute has a value of password.
Example
Try this code »
1. <form>
2. <label for="user-pwd">Password:</label>
3. <input type="password" name="user-password" id="user-pwd">
4. </form>
— The output of the above example will look something like this:
Radio Buttons
Radio buttons are used to let the user select exactly one option from a pre-defined set of options.
It is created using an <input> element whose type attribute has a value of radio.
Example
Try this code »
Note: If you want to allow your user to select more than one option at the same time you should
use the check boxes instead.
Checkboxes
Checkboxes allows the user to select one or more option from a pre-defined set of options. It is
created using an <input> element whose type attribute has a value of checkbox.
Example
Try this code »
1. <form>
2. <input type="checkbox" name="sports" id="soccer">
3. <label for="soccer">Soccer</label>
4. <input type="checkbox" name="sports" id="cricket">
5. <label for="cricket">Cricket</label>
6. <input type="checkbox" name="sports" id="baseball">
7. <label for="baseball">Baseball</label>
8. </form>
— The output of the above example will look something like this:
This is also created using an <input> element, whose type attribute value is set to file.
Example
Try this code »
1. <form>
2. <label for="file-select">Upload:</label>
3. <input type="file" name="upload" id="file-select">
4. </form>
— The output of the above example will look something like this:
Textarea
Textarea is a multiple-line text input control that allows a user to enter more than one line of text.
Multi-line text input controls are created using an <textarea> element.
Example
Try this code »
1. <form>
2. <label for="address">Address:</label>
3. <textarea rows="3" cols="30" name="address" id="address"></textarea>
4. </form>
— The output of the above example will look something like this:
Select Boxes
A select box is a dropdown list of options that allows user to select one or more option from a
pull-down list of options. Select box is created using the <select> element
and <option> element. The option elements within the <select> element define each list item.
Example
Try this code »
1. <form>
2. <label for="city">City:</label>
3. <select name="city" id="city">
4. <option value="sydney">Sydney</option>
5. <option value="melbourne">Melbourne</option>
6. <option value="cromwell">Cromwell</option>
7. </select>
8. </form>
— The output of the above example will look something like this:
Example
Try this code »
Type your name in the text field above, and click on submit button to see it in action.
<label for="username">Name:</label>
</form>
<form>
<label for="address">Address:</label>
</form>
<form>
<label for="username">City:</label>
<form>
<label for="username">State:</label>
<form>
<label for="username">Pincode:</label>
<form>
<label for="username">magzanine:</label>
<label for="cricket">internet</label>
<label for="baseball">ict</label>
<label for="baseball">multimedia</label>
</form
<form>
<label for="city">subscription:</label>
<option value="sydney">1</option>
<option value="melbourne">2</option>
</select>
</form>
</form>
5 24 22 5 10 23 24 11 10 22 24
FACEBOOK.COM/TECHVIDEOGURU WEBSITE:-WWW.TECHVIDEOGURU.MOBI YOUTUBE.COM/TECHVIDEOGURU