HTML | Design Form - GeeksforGeeks (2024)

Last Updated : 13 Apr, 2023

Summarize

Comments

Improve

What is HTML Form?

HTML Form is a document that stores information of a user on a web server using interactive controls. An HTML form contains different kinds of information such as username, password, contact number, email id, etc.
The elements used in an HTML form are the check box, input box, radio buttons, submit buttons, etc. Using these elements the information of a user is submitted on a web server.

The form tag is used to create an HTML form.

Example of an HTML Form:

HTML

<!DOCTYPE html>

<html>

<body>

<form>

Username:<br>

<input type="text" name="username">

<br>

Email id:<br>

<input type="text" name="email_id">

<br><br>

<input type="submit" value="Submit">

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (1)

Input Element in HTML Forms: Input Elements are the most common elements which are used in HTML Forms. Various user input fields can be created such as text field, check box, password field, radio button, submit button, etc. The most common input elements are listed below:

Text Field in HTML Forms:The text field is a one-line input field allowing the user to input text. Text Field input controls are created using the “input” element with a type attribute having the value “text”.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example Of Text Field</h3>

<form>

<label for="EMAIL ID">

Email Id:

</label>

<br>

<input type="text" name="Email id"

id="Email id">

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (2)

Number Field in HTML Forms: This field is used to take numbers as input.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example Of Number Field</h3>

<form>

<label for="Age">Age:</label><br>

<input type="number" name="Age" id="Age">

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (3)

Password Field in HTML Forms:Password fields are a type of text field in which the text entered is masked using asterisks or dots for the prevention of user identity from another person who is looking at the screen. Password Field input controls are created using the “input” element with a type attribute having the value “password”.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of Password Field</h3>

<form>

<label for="user-password">

Password:

</label><br>

<input type="password" name="user-pwd"

id="user-password">

</form>

</body>

</html>

 
 

Output:
HTML | Design Form - GeeksforGeeks (4)
Radio Buttons in HTML Form:Radio Buttons are used to let the user select exactly one option from a list of predefined options. Radio Button input controls are created using the “input” element with a type attribute having the value as “radio”.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of Radio Buttons</h3>

<form>

SELECT GENDER

<br>

<input type="radio" name="gender" id="male">

<label for="male">Male</label><br>

<input type="radio" name="gender" id="female">

<label for="female">Female</label>

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (5)

Checkboxes in HTML Form:Checkboxes are used to let the user select one or more options from a pre-defined set of options. Checkbox input controls are created using the “input” element with a type attribute having the value as “checkbox”.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of HTML Checkboxes</h3>

<form>

<b>SELECT SUBJECTS</b>

<br>

<input type="checkbox" name="subject" id="maths">

<label for="maths">Maths</label>

<input type="checkbox" name="subject" id="science">

<label for="science">Science</label>

<input type="checkbox" name="subject" id="english">

<label for="english">English</label>

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (6)

File select boxes in HTML Forms: File select boxes are used to allow the user to select a local file and send it as an attachment to the web server. It is similar to a text box with a button that allows the user to browse for a file. Instead of browsing for the file, the path and the name of the file can also be written. File select boxes are created using the “input” element with a type attribute having the value as “file”.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of a File Select Box</h3>

<form>

<label for="fileselect">Upload:</label>

<input type="file" name="upload"

id="fileselect">

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (7)

Text area in an HTML Form: Text Area is a multiple-line text input control that allows the user to provide a description or text in multiple lines. A Text Area input control is created using the “textarea” element.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of a Text Area Box</h3>

<form>

<label for="Description">Description:</label>

<textarea rows="5" cols="50" name="Description"

id="Description">

</textarea>

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (8)

Select Boxes in HTML Forms: Select boxes are used to allow users to select one or more than one option from a pull-down list of options. Select boxes are created using two elements which are “select” and “option”. List items are defined within the select element.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of a Select Box</h3>

<form>

<label for="country">Country:</label>

<select name="country" id="country">

<option value="India">India</option>

<option value="Sri Lanka">Sri Lanka</option>

<option value="Australia">Australia</option>

</select>

</form>

</body>

</html>

 
 

Output:

HTML | Design Form - GeeksforGeeks (9)

HTML | Design Form - GeeksforGeeks (10)

Reset And Submit Buttons: The Submit Button allows the user to send the form data to the web server. The Reset Button is used to reset the form data and use the default values.

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of a Submit And Reset Button</h3>

<form action="test.php" method="post" id="users">

<label for="username">Username:</label>

<input type="text" name="username" id="Username">

<input type="submit" value="Submit">

<input type="reset" value="Reset">

</form>

</body>

</html>

 
 

Output:
HTML | Design Form - GeeksforGeeks (11)

Attributes Used in HTML Forms:

The Action Attribute:The action to be performed after the submission of the form is decided by the action attribute. Generally, the form data is sent to a webpage on the web server after the user clicks on the submit button.

Example:

HTML | Design Form - GeeksforGeeks (12)

HTML

<!DOCTYPE html>

<html>

<body>

<h3>Example of a Submit And Reset Button</h3>

<form action="test.php" method="post" id="users">

<label for="username">Username:</label>

<input type="text" name="username" id="Username">

<input type="submit" value="Submit">

<input type="reset" value="Reset">

</form>

</body>

</html>

 
 
If you click the submit button, the form datawould be sent to a page called test.php .

The Target Attribute in HTML Forms:The Target attribute is used to specify whether the submitted result will open in the current window, a new tab, or a new frame. The default value used is “self” which results in the form submission in the same window. For making the form result open in a new browser tab, the value should be set to “blank”.

HTML

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank">

Username:<br>

<input type="text" name="username">

<br>

Password:<br>

<input type="password" name="password">

<br><br>

<input type="submit" value="Submit">

</form>

</body>

</html>

 
 
After clicking on the submit button, the result will open in a new browser tab.

Name Attribute in Html Forms:The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all.

HTML

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank">

Username:<br>

<input type="text">

<br>

Password:<br>

<input type="password" name="password">

<br><br>

<input type="submit" value="Submit">

</form>

</body>

</html>

 
 
In the above code, after clicking the submit button, the form data willbe sent to a page called /test.php. The data sent would not include theusername input field data since the name attribute is omitted.

The Method Attribute: It is used to specify the HTTP method used to send data while submitting the form. There are two kinds of HTTP Methods, which are GET and POST.

The GET Method:

HTML

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank"

method="GET">

Username:<br>

<input type="text" name="username">

<br>

Password:<br>

<input type="password" name="password">

<br><br>

<input type="submit" value="Submit">

</form>

</body>

</html>

 
 
In the GET method, after the submission of the form, the form values will be visible in the address bar of the new browser tab.

The Post Method:

HTML

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank"

method="post">

Username:<br>

<input type="text" name="username">

<br>

Password:<br>

<input type="password" name="password">

<br><br>

<input type="submit" value="Submit">

</form>

</body>

</html>

 
 
In the post method, after the submission of the form, the form valueswill not be visible in the address bar of the new browser tab as it wasvisible in the GET method.

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

HTML is the foundation of webpages and is used for webpage development by structuring websites and web apps. You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.



Please Login to comment...

HTML | Design Form - GeeksforGeeks (2024)
Top Articles
Client Retention For Financial Advisors: What Clients Seem To Really Want
Reinsurance - Definition, What is Reinsurance, Advantages of Reinsurance, and Latest News - ClearTax
Main Moon Ilion Menu
J & D E-Gitarre 905 HSS Bat Mark Goth Black bei uns günstig einkaufen
Goodbye Horses: The Many Lives of Q Lazzarus
Ross Dress For Less Hiring Near Me
Is Sportsurge Safe and Legal in 2024? Any Alternatives?
Aces Fmc Charting
Www Thechristhospital Billpay
Acbl Homeport
Mikayla Campinos Videos: A Deep Dive Into The Rising Star
Hardly Antonyms
Bernie Platt, former Cherry Hill mayor and funeral home magnate, has died at 90
Uc Santa Cruz Events
Alaska Bücher in der richtigen Reihenfolge
Tripadvisor Near Me
Craigslist Pets Southern Md
Everything You Need to Know About Holly by Stephen King
Kris Carolla Obituary
7543460065
iLuv Aud Click: Tragbarer Wi-Fi-Lautsprecher für Amazons Alexa - Portable Echo Alternative
Kiddle Encyclopedia
Lowes Undermount Kitchen Sinks
Iroquois Amphitheater Louisville Ky Seating Chart
Craigslist Wilkes Barre Pa Pets
Idle Skilling Ascension
Kitchen Exhaust Cleaning Companies Clearwater
Lindy Kendra Scott Obituary
Mobile crane from the Netherlands, used mobile crane for sale from the Netherlands
Bi State Schedule
Davita Salary
Cbs Trade Value Chart Week 10
Phone number detective
#1 | Rottweiler Puppies For Sale In New York | Uptown
Boggle BrainBusters: Find 7 States | BOOMER Magazine
Mohave County Jobs Craigslist
Gifford Christmas Craft Show 2022
Mid America Irish Dance Voy
Wunderground Orlando
O'reilly's Palmyra Missouri
Cocaine Bear Showtimes Near Cinemark Hollywood Movies 20
Shipping Container Storage Containers 40'HCs - general for sale - by dealer - craigslist
Does Target Have Slime Lickers
Honkai Star Rail Aha Stuffed Toy
The Sports Academy - 101 Glenwest Drive, Glen Carbon, Illinois 62034 - Guide
Oefenpakket & Hoorcolleges Diagnostiek | WorldSupporter
Goosetown Communications Guilford Ct
Hy-Vee, Inc. hiring Market Grille Express Assistant Department Manager in New Hope, MN | LinkedIn
Factorio Green Circuit Setup
Scholar Dollar Nmsu
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6187

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.