CSS Portal

HTML enctype Attribute

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

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

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 information will show you the current browser support for the HTML enctype attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 28th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!