A webform, web form or HTML form on a
web page
A web page (or webpage) is a World Wide Web, Web document that is accessed in a web browser. A website typically consists of many web pages hyperlink, linked together under a common domain name. The term "web page" is therefore a metaphor of pap ...
allows a user to enter data that is sent to a
server for processing. Forms can resemble
paper
Paper is a thin sheet material produced by mechanically or chemically processing cellulose fibres derived from wood, Textile, rags, poaceae, grasses, Feces#Other uses, herbivore dung, or other vegetable sources in water. Once the water is dra ...
or
database
In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
forms because web users fill out the forms using
checkboxes,
radio buttons, or
text fields. For example, forms can be used to enter
shipping
Freight transport, also referred to as freight forwarding, is the physical process of transporting commodities and merchandise goods and cargo. The term shipping originally referred to transport by sea but in American English, it has been ...
or
credit card data to order a product, or can be used to retrieve search results from a
search engine
A search engine is a software system that provides hyperlinks to web pages, and other relevant information on World Wide Web, the Web in response to a user's web query, query. The user enters a query in a web browser or a mobile app, and the sea ...
.
Description

Forms are enclosed in the
HTML
Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
<form>
element. This HTML element specifies the
communication endpoint
A communication endpoint is a type of Node (networking), communication network node. It is an interface exposed by a communicating party or by a communication channel. An example of the latter type of a communication endpoint is a publish–subscr ...
the data entered into the form should be submitted to, and the
method
Method (, methodos, from μετά/meta "in pursuit or quest of" + ὁδός/hodos "a method, system; a way or manner" of doing, saying, etc.), literally means a pursuit of knowledge, investigation, mode of prosecuting such inquiry, or system. In re ...
of submitting the data,
GET
or
POST
.
Elements
Forms can be made up of standard
graphical user interface
A graphical user interface, or GUI, is a form of user interface that allows user (computing), users to human–computer interaction, interact with electronic devices through Graphics, graphical icon (computing), icons and visual indicators such ...
elements:
*
<text>
— a simple
text box that allows input of a single line of text.
*
<email>
- a type of
<text>
that requires a partially validated email address
*
<number>
- a type of
<text>
that requires a number
*
<password>
— similar to
<text>
, it is used for security purposes, in which the characters typed in are invisible or replaced by symbols such as *
*
<radio>
— a
radio button
A radio button or option button is a graphical control element that allows the user to choose only one of a predefined set of mutually exclusive options. The singular property of a radio button makes it distinct from checkboxes, where the user ...
*
<file>
— a
file select control for uploading a file
*
<reset>
— a
reset button that, when activated, tells the browser to restore the values of the current form, to their initial values.
*
<submit>
— a
button
A button is a fastener that joins two pieces of fabric together by slipping through a loop or by sliding through a buttonhole.
In modern clothing and fashion design, buttons are commonly made of plastic but also may be made of metal, wood, or ...
that tells the browser to take action on the form (typically to send it to a server)
*
<textarea>
— much like the
<text>
input field except a
<textarea>
allows for multiple rows of data to be shown and entered
*
<select>
— a
drop-down list that displays a list of items a user can select from
The sample image on the right shows most of these elements:
* a text box asking for your name
* a pair of radio buttons asking you to choose between gender values
* a
select box giving you a list of eye colors to choose from
* a pair of check boxes to click on if they apply to you
* a text area to describe your athletic ability
* a submit button to send current form values to the server
These basic elements provide the most common
graphical user interface
A graphical user interface, or GUI, is a form of user interface that allows user (computing), users to human–computer interaction, interact with electronic devices through Graphics, graphical icon (computing), icons and visual indicators such ...
(GUI) elements, but not all. For example, there are no equivalents to a
tree view or
grid view.
A grid view, however, can be mimicked by using a standard HTML
table with each cell containing a text input element. A tree view could also be mimicked through nested tables or, more
semantically appropriately, nested
lists. In both cases, a
server-side process is responsible for processing the information, while JavaScript handles the user-interaction. Implementations of these interface elements are available through
JavaScript libraries such as
jQuery.
HTML 4 introduced the
<label>
tag, which is intended to represent a caption in a user interface, and can be associated with a specific form control by specifying the
id
attribute of the control in the label tag's
for
attribute. This allows labels to stay with their elements when a window is resized and to allow more desktop-like functionality (e.g. clicking a radio button or checkbox's label will activate the associated input element).
HTML 5 introduces a number of input tags that can be represented by other interface elements. Some are based upon text input fields and are intended to input and validate specific common data. These include
<email>
to enter email addresses,
<tel>
for telephone numbers,
<number>
for numeric values. There are additional attributes to specify required fields, fields that should have keyboard
focus when the web page containing the form is loaded, and placeholder text that is displayed within the field but is not user input (such as the 'Search' text displayed in many search input fields before a search term is entered). These tasks used to be handled with
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
, but had become so common that support for them was added to the standard. The
<date>
input type displays a calendar from which the user can select a date or date range. And the
color
input type can be represented as an input text simply checking the value entered is a correct
hexadecimal
Hexadecimal (also known as base-16 or simply hex) is a Numeral system#Positional systems in detail, positional numeral system that represents numbers using a radix (base) of sixteen. Unlike the decimal system representing numbers using ten symbo ...
representation of a color, according to the specification, or a color picker widget (the latter being the solution used in most browsers which support this attribute).
Submission
When data that has been entered into HTML forms is submitted, the names and values in the form elements are encoded and sent to the server in an
HTTP
HTTP (Hypertext Transfer Protocol) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, wher ...
request message using
GET or
POST. Historically, an
email
Electronic mail (usually shortened to email; alternatively hyphenated e-mail) is a method of transmitting and receiving Digital media, digital messages using electronics, electronic devices over a computer network. It was conceived in the ...
transport was also used. The default
MIME type (internet media type),
application/x-www-form-urlencoded, is based on a very early version of the general URI
percent-encoding
URL encoding, officially known as percent-encoding, is a method to binary-to-text encoding, encode arbitrary data in a uniform resource identifier (URI) using only the ASCII, US-ASCII characters legal within a URI. Although it is known as ''URL en ...
rules, with a number of modifications such as
newline
A newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or ...
normalization and replacing spaces with "
+
" instead of "
%20
". Another possible encoding, Internet media type
multipart/form-data, is also available and is common for POST-based file submissions.
Use with programming languages
Forms are usually combined with programs written in various
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
to allow
developers to create dynamic
web site
A website (also written as a web site) is any web page whose content is identified by a common domain name and is published on at least one web server. Websites are typically dedicated to a particular topic or purpose, such as news, education, ...
s. The most popular languages include both client-side and/or server-side languages.
Although any programming language can be used on the server to process a form's data, the most commonly used languages are
scripting languages
In computing, a script is a relatively short and simple set of instructions that typically automation, automate an otherwise manual process. The act of writing a script is called scripting. A scripting language or script language is a programming ...
, which tend to have stronger
string
String or strings may refer to:
*String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects
Arts, entertainment, and media Films
* ''Strings'' (1991 film), a Canadian anim ...
handling functionality than programming languages such as C, and also have automatic
memory management
Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of Resource management (computing), resource management applied to computer memory. The essential requirement of memory manag ...
which helps to prevent
buffer overrun attacks.
Client-side
The
''de facto'' client-side scripting language for web sites is
JavaScript
JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior.
Web browsers have ...
.
Using JavaScript on the
Document Object Model
The Document Object Model (DOM) is a cros s-platform and language-independent API that treats an HTML or XML document as a tree structure wherein each node is an object representing a part of the document. The DOM represents a document with ...
(DOM) leads to the method of
Dynamic HTML that allows dynamic creation and modification of a web page within the browser.
While client-side languages used in conjunction with forms are limited, they often can serve to do pre-
validation of the form data and/or to prepare the form data to send to a server-side program. This usage is being replaced, however, by
HTML5
HTML5 (Hypertext Markup Language 5) is a markup language used for structuring and presenting hypertext documents on the World Wide Web. It was the fifth and final major HTML version that is now a retired World Wide Web Consortium (W3C) recommend ...
's new
input
field types and
required
attribute.
Server-side execution
Server-side code can do a vast assortment of tasks to create dynamic web sites that, for technical or security reasons, client-side code cannot — from
authenticating a
login
In computer security, logging in (or logging on, signing in, or signing on) is the process by which an individual gains access to a computer system or program by identifying and authenticating themselves.
Typically, user credential ...
, to retrieving and storing data in a
database
In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
, to
spell checking, to sending
e-mail
Electronic mail (usually shortened to email; alternatively hyphenated e-mail) is a method of transmitting and receiving Digital media, digital messages using electronics, electronic devices over a computer network. It was conceived in the ...
. A significant advantage to server-side over client-side execution is the concentration of functionality onto the server rather than relying on different
web browser
A web browser, often shortened to browser, is an application for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's scr ...
s to implement various functions in consistent,
standardized
Standardization (American English) or standardisation (British English) is the process of implementing and developing technical standards based on the consensus of different parties that include firms, users, interest groups, standards organiza ...
ways. In addition, processing forms on a server often results in increased security if server-side execution is designed not to trust the data supplied by the client and includes such techniques as
HTML sanitization. One disadvantage to server side code is
scalability
Scalability is the property of a system to handle a growing amount of work. One definition for software systems specifies that this may be done by adding resources to the system.
In an economic context, a scalable business model implies that ...
—server side processing for all users occurs on the server, while client side processing occurs on individual client computers.
Interpreted languages
Some of the
interpreted language
In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An inter ...
s commonly used to design interactive forms in web development are
PHP,
Python,
Ruby
Ruby is a pinkish-red-to-blood-red-colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapph ...
,
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".
Perl was developed ...
,
JSP,
Adobe ColdFusion and some of the compiled languages commonly used are
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
and
C# with
ASP.NET.
PHP
PHP is one very common language used for server-side "programming" and is one of the few languages created specifically for
web programming.
To use PHP with an HTML form, the URL of the PHP script is specified in the
action
attribute of the form tag. The target PHP file then accesses the data passed by the form through PHP's
$_POST or
$_GET variables, depending on the value of the
method
attribute used in the form. Here is a basic form handler PHP script that will display the contents of the input field on the page:
Form
Output
The sample code above uses PHP's
filter_input() function to sanitize the user's input before inserting it onto the page. Simply printing (echoing) user input to the browser without checking it first is something that should be avoided in secure forms processors: if a user entered the JavaScript code
into the field, the browser would execute the script on the page, just as if it had been coded by the developer; malicious code could be executed this way.
filter_input() was introduced in PHP 5.2. Users of earlier PHP versions could use the
htmlspecialchars() function, or
regular expressions
A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of character (computing), characters that specifies a pattern matching, match pattern in string (computer science), text. Usually ...
to sanitize the user input before doing anything with it.
Perl programming language
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".
Perl was developed ...
is another language often used for
web development. Perl scripts are traditionally used as
Common Gateway Interface
file:Common Gateway Interface logo.svg, The official CGI logo from the spec announcement
In computing, Common Gateway Interface (CGI) is an interface specification that enables web servers to execute an external program to process HTTP or HTTPS ...
applications (CGIs). In fact, Perl is such a common way to write CGIs that the two are often confused. CGIs may be written in other languages than Perl (compatibility with multiple languages is a design goal of the CGI protocol) and there are other ways to make Perl scripts interoperate with a
web server
A web server is computer software and underlying Computer hardware, hardware that accepts requests via Hypertext Transfer Protocol, HTTP (the network protocol created to distribute web content) or its secure variant HTTPS. A user agent, co ...
than using CGI (such as
FastCGI,
Plack or
Apache
The Apache ( ) are several Southern Athabaskan language-speaking peoples of the Southwestern United States, Southwest, the Southern Plains and Northern Mexico. They are linguistically related to the Navajo. They migrated from the Athabascan ho ...
's
mod_perl).
Perl CGIs were once a very common way to write
web application
A web application (or web app) is application software that is created with web technologies and runs via a web browser. Web applications emerged during the late 1990s and allowed for the server to dynamically build a response to the request, ...
s. However, many web hosts today effectively only support PHP, and developers of web applications often seek compatibility with them.
A modern Perl 5 CGI using the CGI module with a form similar to the one above might look like:
#!/usr/bin/env perl
use strict;
use CGI qw(:standard);
my $name = param("first_name");
print header;
print html(
body(
p("Hello, $name!"),
),
);
Form-to-email scripts
Among the simplest and most commonly needed types of server-side script is that which simply emails the contents of a submitted form. This kind of script is frequently exploited by
spammers, however, and many of the most popular form-to-email scripts in use are vulnerable to hijacking for the purpose of sending spam emails. One of the most popular scripts of this type wa
"FormMail.pl"made by
Matt's Script Archive. Today, this script is no longer widely used in new development due to lack of updates, security concerns, and difficulty of configuration.
Form builders
Some companies offer forms as a
hosted service. Usually, these companies give some kind of visual editor, reporting tools and infrastructure to create and host the forms, that can be embedded into webpages.
Web hosting
A web hosting service is a type of Internet hosting service that hosts websites for clients, i.e. it offers the facilities required for them to create and maintain a site and makes it accessible on the World Wide Web. Companies providing web ho ...
companies provide templates to their clients as an add-on service. Other form hosting services offer free contact forms that a user can install on their own website by pasting the service's code into the site's HTML.
History
HTML forms were first implemented by the
Viola
The viola ( , () ) is a string instrument of the violin family, and is usually bowed when played. Violas are slightly larger than violins, and have a lower and deeper sound. Since the 18th century, it has been the middle or alto voice of the ...
browser.
See also
*
CAPTCHA
Completely Automated Public Turing Test to tell Computers and Humans Apart (CAPTCHA) ( ) is a type of challenge–response authentication, challenge–response turing test used in computing to determine whether the user is human in order to de ...
*
Postback
*
XForms
XForms is an XML format used for collecting inputs from web forms. XForms was designed to be the next generation of HTML / XHTML forms, but is generic enough that it can also be used in a standalone manner or with presentation languages other tha ...
*
HTML
Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
References
External links
Forms in HTML documents the
W3C
The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. Founded in 1994 by Tim Berners-Lee, the consortium is made up of member organizations that maintain full-time staff working together in ...
's spec page for forms in HTML 4.
HTML5 forms specification*
Wikibooks: HyperText Markup Language/Forms
Try out HTML properties.
{{Use dmy dates, date=August 2024
User interface techniques
HTML tags
HTML