HTML enctype Attribute

Description

The enctype attribute in HTML forms specifies how the form data should be encoded when submitting it to the server. This encoding type is crucial when the form includes file uploads or when special characters need to be handled properly. By setting this attribute, developers can control the format in which the data is sent, ensuring compatibility and correct handling by the server. It's especially important in forms that require different types of inputs, including binary data, as it affects how the server processes and interprets the incoming form data.

Syntax

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

Values

  • application/x-www-form-urlencodedThis is the default encoding and is used for most forms. It encodes spaces as + symbols and special characters as %XX, where XX is the ASCII hex value of the character. This encoding type is suitable for forms that do not include file uploads.
  • multipart/form-dataThis encoding type is necessary when a form includes any <input type="file"> elements, as it allows files to be sent to the server. It does not encode characters. Instead, it sends each form field as a block of data (a "part"), with a user agent-defined delimiter ("boundary") separating each part.
  • text/plainA less commonly used encoding type that sends the data without encoding it at all. Spaces are converted to + signs, but other than that, characters are not encoded. This type is not recommended for production use but can be useful for debugging purposes.

Applies To

The enctype attribute can be used on the following html elements.

Example

<form action="formscript.php" method="post" enctype="multipart/form-data">
<label for="name">Your Name:</label><br>
<input type="text" id="name" name="name"><br><br>
<label for="file">Upload File:</label><br>
<input type="file" id="file" name="file"><br><br>
<button type="submit">Submit</button>
</form>

Browser Support

The following table will show you the current browser support for the HTML enctype Attribute.

Desktop
Edge Chrome Firefox Opera Safari
1211153
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18414214.4

Last updated by CSSPortal on: 28th March 2024