Html Form Attributes


HTML forms are used to submit data to a server. Forms can have various attributes that control behavior, validation, and data submission.

 

Syntax

<form action="submit.php" method="post">
  <!-- form elements go here -->
</form> 

html-form-attribute


HTML Form Attributes

action

Defines where to send the form data when submitted.

 

 <form action="submit.php">

Example

<form action="/register">
  <input type="text" name="username">
  <input type="submit">
</form> 

method

Specifies the HTTP method to use (GET or POST).

 

 <form action="submit.php" method="post" >

Example

<form action="/login" method="post">
  <input type="text" name="user">
  <input type="password" name="pass">
  <input type="submit">
</form> 

target

Determines where to display the response after submitting.

<form target="_blank">

Example

<form action="/results" target="_blank">
  <input type="search" name="query">
  <input type="submit" value="Search">
</form>

Values:

  • _self (default) – same tab
  • _blank – new tab
  • _parent – parent frame
  • _top – full window

enctype

Defines how form data should be encoded when sent to the server.

Syntax:

<form method="post" enctype="multipart/form-data"> 

Common values:

  • application/x-www-form-urlencoded (default)
  • multipart/form-data (for file uploads)
  • text/plain

Example

 <form action="/upload" method="post" enctype="multipart/form-data">
  <input type="file" name="file">
  <input type="submit">
</form>

Attribute Description Common Values
action URL to send data /submit, /login, submit.php
method HTTP method get, post
target Where to display response _self, _blank, _parent, _top
enctype Data encoding type application/x-www-form-urlencoded, multipart/form-data
autocomplete Suggest saved inputs on, off
novalidate Skips validation Boolean attribute
name Name of form (used in JavaScript) Any string
accept-charset Character set for submission UTF-8, ISO-8859-1



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.