Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
HTML Form
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. HTML Tutorials
  3. HTML Form

HTML Tutorial

Basic HTML Fundamentals

  • HTML Table Content
  • Introduction To HTML
  • What Is HTML
  • HTML Tags
  • HTML Formatting
  • HTML Heading
  • HTML Paragraph
  • HTML Anchor
  • HTML Image
  • HTML Table
  • HTML Lists
  • HTML Ordered List
  • HTML Unordered List
  • HTML Description List
  • HTML Form

HTML Tags

  • Marquee HTML
  • HTML Textarea
  • HTML Quotes
  • HTML Style
  • HTML Title Or HTML Doctype
  • HTML Div Tag
  • HTML Pre Tag
  • HTML Code Tag
  • HTML Label Tag
  • HTML Input Tag
  • HTML Button Tag
  • HTML Hr Tag
  • HTML Br Tag
  • HTML Script Tag
  • HTML NoScript Tag
  • HTML Bold Tag

HTML Form

HTML Form

An HTML form is a section of a document which contains controls such as text fields, password fields, checkboxes, radio buttons, submit button, menus etc.

An HTML form facilitates the user to enter data that is to be sent to the server for processing.

Why use HTML Form

HTML forms are required if you want to collect some data from of the site visitor.

For example: If a user want to purchase some items on internet, he/she must fill the form such as shipping address and credit/debit card details so that item can be sent to the given address.

HTML Form Syntax

<form action="server url" method="get">  
  //input controls e.g. textfield, textarea, radiobutton, button  
</form>  

OR

<form action="server url" method="post">  
  //input controls e.g. textfield, textarea, radiobutton, button  
</form> 

HTML Form Tags

List of HTML 5 form tags.

Tag Description
<form> It defines an HTML form to enter inputs by the used side.
<input> It defines an input control.
<textarea> It defines a multi-line input control.
<label> It defines a label for an input element.
<fieldset> It groups the related element in a form.
<legend> It defines a caption for a <fieldset> element.
<select> It defines a drop-down list.
<optgroup> It defines a group of related options in a drop-down list.
<option> It defines an option in a drop-down list.
<button> It defines a clickable button.

HTML 5 Form Tags

List of HTML 5 form tags.

Tag Description
<datalist> It specifies a list of pre-defined options for input control.
<keygen> It defines a key-pair generator field for forms.
<output> It defines the result of a calculation.

HTML TextField Control

The type="text" attribute of input tag creates textfield control also known as single line textfield control. The name attribute is optional, but it is required for the server side component such as JSP, ASP, PHP etc.

<form>  
    First Name: <input type="text" name="firstname"/> <br/>  
    Last Name:  <input type="text" name="lastname"/> <br/>  
</form>

Label Tag in Form

It is considered better to have label in form. As it makes the code parser/browser/user friendly.

If you click on the label tag, it will focus on the text control. To do so, you need to have for attribute in label tag that must be same as id attribute of input tag.

<form>  
    <label for="firstname">First Name: </label>  
              <input type="text" id="firstname" name="firstname"/> <br/>  
   <label for="lastname">Last Name: </label>  
              <input type="text" id="lastname" name="lastname"/> <br/>  
 </form>

 HTML Password Field Control

The password is not visible to the user in password field control.

<form>  
    <label for="password">Password: </label>  
    <input type="password" id="password" name="password"/> <br/>  
</form> 

HTML 5 Email Field Control

The email field in new in HTML 5. It validates the text for correct email address. You must use @ and . in this field.

<form>  
    <label for="email">Email: </label>  
    <input type="email" id="email" name="email"/> <br/>  
</form>  

Radio Button Control

The radio button is used to select one from multiple options. It is used in gender, quiz questions etc.

If you use one name for all the radio buttons, only one radio button can be selected at a time.

<form>  
    <label for="gender">Gender: </label>  
    <input type="radio" id="gender" name="gender" value="male"/>Male  
    <input type="radio" id="gender" name="gender" value="female"/>Female <br/>  
</form>  

Checkbox Control

The checkbox control is used to check multiple options from given checkboxes.

<form>  
Courses:<br>  
    <input type="checkbox" id="java" name="java" value="java"/>  
    <label for="java">Java</label>  
    <input type="checkbox" id="sql" name="sql" value="sql"/>  
    <label for="sql">Sql</label>  
    <input type="checkbox" id="php" name="php" value="php"/>  
    <label for="php">Php</label>  
</form>  

HTML Form Example

Simple example of creating HTML form.

<form action="#">  
<table>  
<tr>  
    <td class="tdLabel"><label for="register_name" class="label">Enter name:</label></td>  
    <td><input type="text" name="name" value="" id="register_name" style="width:160px"/></td>  
</tr>  
<tr>  
    <td class="tdLabel"><label for="register_password" class="label">Enter password:</label></td>  
    <td><input type="password" name="password" id="register_password" style="width:160px"/></td>  
</tr>  
<tr>  
    <td class="tdLabel"><label for="register_email" class="label">Enter Email:</label></td>  
    <td  
><input type="email" name="email" value="" id="register_email" style="width:160px"/></td>  
</tr>  
<tr>  
    <td class="tdLabel"><label for="register_gender" class="label">Enter Gender:</label></td>  
    <td>  
<input type="radio" name="gender" id="register_gendermale" value="male"/>  
<label for="register_gendermale">male</label>  
<input type="radio" name="gender" id="register_genderfemale" value="female"/>  
<label for="register_genderfemale">female</label>  
    </td>  
</tr>  
<tr>  
    <td class="tdLabel"><label for="register_country" class="label">Select Country:</label></td>  
    <td><select name="country" id="register_country" style="width:160px">  
    <option value="india">india</option>  
    <option value="pakistan">pakistan</option>  
    <option value="africa">africa</option>  
    <option value="china">china</option>  
    <option value="other">other</option>  
</select>  
</td>  
</tr>  
<tr>  
    <td colspan="2"><div align="right"><input type="submit" id="register_0" value="register"/>  
</div></td>  
</tr>  
</table>  
</form>  

Supporting Browsers

Element  Chrome  IE  Firefox  Opera  Safari
<h1> to <h6> Yes Yes Yes Yes Yes
Series: HTML Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
html form drop down html registration form code html form input types html form design html form design examples with code html form checkbox html form templates html form post

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.