1. Introduction to Forms
Forms in HTML are an essential tool for user interaction with web pages. They allow collecting
information from users, whether it's text, selecting options from a list, uploading files, or other data, which can then
be sent to the server for processing. In HTML, forms are created using a bunch of elements, each
designed for a specific type of input. The main form element is
<form>
, which includes other elements like <input>
, <textarea>
,
<button>
, <select>
, and more.
Basic Form Elements
Form elements allow you to create input fields, buttons, dropdown lists, and other interface components through which users can provide data. Here are the main tags used in forms:
<form>
— the main container for all form elements. It defines where and how the data is sent.<input>
— a universal element for creating input fields of various types (text, password, radio buttons, checkboxes, etc.).<label>
— an element associated with an input field, used to describe its purpose.<textarea>
— a field for entering multi-line text.<button>
— a button for submitting the form or performing other actions.<select>
and <option> — a dropdown list where users can select one or more options.
Example of a Simple Form
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<button type="submit">Submit</button>
</form>
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<button type="submit">Submit</button>
</form>
GO TO FULL VERSION