HTML Forms

HTML forms are used to capture user input. They are composed of other form elements like text fields, submit buttons, checkboxes, radio buttons and more.

HTML <form> Element

The HTML <form> element is usded to define a form to collect user input.

HTML <form> Example

<form name=”myform” action=”script.php” method=”post”>
First Name<br>
<input type=”text” /><br>
Last Name<br>
<input type=”text” /><br>
<input type=”submit” value=”Submit” />

HTML Forms Action Attribute

The action attribute is used to define the action to be executed when the form is submitted. Normally, the form data is sent to another web page which contain a server-side script to handle form data. If the action attribute is not defined, the action is set to the current page.

HTML Forms Target Attribute

The target attribute is used to submit form in current window, in a new browser tab, or in a frame. By default it is set to “_self” which submit the form in current window. “_blank” is used to submit form in a new browser tab.


<form action=”script.php” target=”_blank”>

HTML Forms Method Attribute

The method attribute is used to specify the HTTP method (GET or POST) to submit the form data.

HTML Forms GET Method

The default method when submitting form data is GET. Data is submitted as query string with the url and will be visible in the address bar of the web page. You should never use GET method to send sensitive data. Also the length of a URL is limited.


<form action=”script.php” method=”get”>

HTML Forms POST Method

The POST method does not display the submitted form data in the page address field. POST method should be used to submit sensitive data. POST has no size limitations, and can be used to send large amounts of data. Form submissions with POST cannot be bookmarked.


<form action=”script.php” method=”post”>