html
  1. html-form-tag

HTML <form> Tag

  • The <form> tag in HTML is used to create an interactive form on a web page.
  • Forms are fundamental for gathering user input, such as text, selections, checkboxes, radio buttons, and more.
  • The <form> tag acts as a container for these input elements.

<form action="/submit-form" method="post">
    <label for="username">Username:</label>
    <input type="text" id="username" name="username"><br><br>
    
    <label for="password">Password:</label>
    <input type="password" id="password" name="password"><br><br>
    
    <input type="submit" value="Submit">
</form>
Try Playground

Form Attributes

  • action: Specifies the URL or file name where the form data will be submitted. It could be a server endpoint, a script, or a file.
  • method: Defines the HTTP method used to send the form data to the server. It could be "get" or "post". method="post" is commonly used for sending sensitive information as it's more secure than "get".
  • target: Specifies where to display the response received after submitting the form. For instance, _blank will open the response in a new window.
  • enctype: Defines how the form data should be encoded before sending it to the server. For file uploads, you might use enctype="multipart/form-data".
  • autocomplete: Controls whether the browser should automatically complete the form. Values can be "on" or "off".
  • name: Provides a name for the form. This is used when scripting with JavaScript or for identifying the form in the document.
Published on: