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.



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>

Using enctype

The enctype attribute specifies how submitted form data is encoded.

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


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



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:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

 Back to <form>

Last updated on Sep 30, 2023