Advertisement

Google Ad Slot: content-top

Form

~1 min read · HTML
On this page

In HTML, the <form> element is used to create a form for collecting user input, which is then sent to a server for processing. Forms can contain various types of input elements like text fields, checkboxes, radio buttons, and submit buttons.

Basic Structure of a Form




Try it yourself

Key Attributes of the <form> Element:

Action:

action: Specifies the URL where the form data will be sent for processing.

Method:

method: Defines how the form data is sent to the server. Common values:

  • GET: Appends form data to the URL (visible in the URL).
  • POST: Sends form data as a separate request body (not visible in the URL).

Enctype:

enctype: Specifies how form data should be encoded when submitting it to the server (relevant when method="POST"). Common values:

  • application/x-www-form-urlencoded: Default encoding.
  • multipart/form-data: Required when the form includes file uploads.
  • text/plain: Sends data without any encoding.

Target:

target: Specifies where to display the response after submitting the form. Common values:

  • _self: Opens in the same tab (default).
  • _blank: Opens in a new tab or window.
  • _parent, _top: For controlling frames.

Autocomplete:

autocomplete: Enables or disables autocomplete for the form (on or off).