Computerhelp4all logo Articles AboutTopicsQuizzesComputer Questions & AnswersComputer Terms & DefinitionsActivitiesContact

What Is A HTML Form?

What Is A HTML Form

Date First Published: 1st February 2023

Topic: Web Design & Development

Subtopic: Web Development

Article Type: Computer Terms & Definitions

Difficulty: Medium

Difficulty Level: 5/10

Learn more about what a HTML form is in this article.

In HTML, a form is an interactive element on a webpage used to process and collect user input. The user input is often sent to a server for processing. Forms can contain checkboxes, text fields, ‘radio’ buttons, submit buttons, and more. They can be used to fill out surveys, collect contact information, gather payment and shipping information, allow users to post comments, and perform other functions.

Elements

HTML forms are made up of the following elements:

Form element

The HTML <form> element provides a section to take input from the user. It does not create a form by itself, but it is a container to contain all the required form elements, such as <input>. All the form elements are located within the opening and closing tags.

Input element

This element specifies an input field where users can enter data. Depending on the ‘type’ attribute, the input element can be displayed in lots of different ways. Some ways include:

  • <input type="text"> - Displays a single-line text input field.
  • <input type="radio"> - Displays a ‘radio’ button.
  • <input type="checkbox"> - Displays a checkbox.
  • <input type="submit"> - Displays a submit button.
  • <input type="button"> - Displays a clickable button.

Text fields

The <input type="text"> is used to define a single-line input field for text input.

Labels

The label tag is used to define a label for form elements. For accessibility reasons, it should be used as screen readers will read out loud the label when the user focuses on the input element.

Radio buttons

The <input type="radio"> is used to define a radio button. These circular buttons only allow users to select one of a number of options.

Checkboxes

The <input type="checkbox"> is used to define a checkbox. These allow users to select 0 or multiple choices from a number of options.

Submit buttons

The <input type="submit"> is used to define a button for submitting the form data.

The data is usually submitted to a form handler. This is a file on a server that processes the input and it is specified in the action attribute of the form.

Textarea tag

The textarea tag is used to insert multiple-line text in a form. The size of <textarea> can be specified either using the "rows" or "cols" attribute, or by CSS.

<form> Enter your message:<br> <textarea rows="2" cols="20"></textarea> </form>

Email fields

HTML5 introduces a new email field. It ensures that a valid email address is entered into the field. The symbols ‘@’ and ‘.’ must be used in the field. If it does not contain these symbols, it will return an error message.

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

Password fields

This field is used to enter passwords. The text entered into the field is invisible to the user in the password field.

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

Note: Info Icon

Every input field must have a name attribute to be submitted. Without the name attribute, the value of the input field will not be sent at all.

Example Of A HTML Form

An example of a HTML form to submit a username and a password with the output can be seen below:

<form> <label for="name">Username</label><br> <input type="text" id="username" name="username"><br> <label for="pass">Password</label><br> <input type="Password" id="password" name="password"> <br> <br> <input type="submit" id="submission-button" value="Submit"> </form>







Feedback

  • Is there anything that you disagree with on this page?
  • Are there any spelling, grammatical, or punctuation errors on this page?
  • Are there any broken links or design errors on this page?

If so, it is important that you tell me as soon as possible on this page.