Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <form> enctype Attribute

The enctype attribute on a <form> tag specifies the data encoding to use during a form submission.

This attribute can only be used if the form method is POST.

Example

#

A enctype attribute on a <form> element. The form accepts 'multipart/form-data' which may include uploaded file(s).








<form action="/tutorial/action" method="post" enctype="multipart/form-data"
      onsubmit="alert('Form data has been posted to the server.');return false;">

  <label for="firstname">First name </label> <br />
  <input type="text" id="firstname" name="firstname"> <br />

  <label for="lastname">Last name </label> <br />
  <input type="text" id="lastname" name="lastname"> <br />

  <label for="avatar">Avatar </label> <br />
  <input type="file" id="avatar" name="avatar" 
         accept="image/*"><br /><br />

  <button type="submit">Submit</button>
</form>

Using enctype

The enctype attribute specifies how submitted form data is encoded.

This attribute can only be used with method="post".


Syntax

<form method="post" 
      enctype="application/x-www-form-urlencoded | multipart/form-data | text/plain">

Values

#

Value Description
application/x-www-form-urlencoded The default. All form data characters are encoded before sending to the server.
multipart/form-data Form data characters are encoded before sending to the server. This value should only be used for forms with file upload functionality, i.e. have an input type="file" element.
text/plain Form data characters are not encoded, expect space characters are converted to a "+". This value should not be used, except for debugging purposes.

Browser support

Here is when enctype support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <form>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides