HTML Tutorial - HTML Form Encoding

The enctype attribute specifies how the browser encodes and presents the data to the server.

There are three allowed values for this attribute.

  • application/x-www-form-urlencoded
    Default encoding.
    This encoding cannot be used to upload files to the server.
  • multipart/form-data
    This encoding is used to upload files to the server.
  • text/plain
    This encoding varies between browsers.

To understand how the different encodings work, we created the following form.

  <form method="post" action="">
    <input name="fave" /> 
    <input name="name" />
    <button>Submit Vote</button>
  </form><!--   w w w.  ja v  a  2  s . com-->

Click to view the demo


If using application/x-www-form-urlencoded encoding
The name and value of each data item is encoded using the same scheme that is used to encode URLs. This is how the encoding is applied to the data in the example form:


Special characters are replaced with their HTML entity counterpart. The name of the data item and the value are separated by the equals sign (=) and data/value tuples are separated by the ampersand character (&).


The multipart/form-data encoding tends to be used only for uploading files. Here is how the data from the example form is encoded:


Content-Disposition: form-data; name="fave" YourName
------WebKitFormBoundary2desQWER543CDFGF Content-Disposition: form-data; name="name"
------WebKitFormBoundary2desQWER543CDFGF-- fave=Apple


The mainstream browsers encode data in different ways for this encoding.

Google Chrome encodes data in the same way as for the application/x-www-form-urlencoded scheme, whereas Firefox encodes the data as follows:


Each data item is placed on a line, and special characters are not encoded.