HTML button formenctype Attribute | .com
Home
HTML
JavaScript
CSS
Vue
React
Python3
Java
C
C++
C#
AI
Go
SQL
Linux
VS Code
Bootstrap
Git
Bookmarks
HTML Reference Manual
- HTML Tag List (Alphabetical Order)
- HTML Tag List (Function-Based Order)
- HTML Global Attributes
- HTML Events
- HTML Canvas
- HTML Audio/Video
- Valid HTML DOCTYPES
- HTML Color Names
- HTML Color Picker
- HTML Color Mixer
- HTML Emoji
- HTML Character Sets
- HTML ASCII Reference Manual
- HTML ISO-8859-1 Reference Manual
- HTML Symbol Entities Reference Manual
- HTML URL Encoding Reference Manual
- HTML Language Codes Reference Manual
- HTML Country/Region Codes
- HTTP Status Messages
- HTTP Methods: GET vs POST
- Px/Em Conversion Tool
- Keyboard Shortcuts
HTML Tags
HTML button formenctype Attribute
The formenctype attribute specifies how the form data should be encoded when submitting the form.
This attribute is only used with buttons of type submit and image. It overrides the enctype attribute of the <form> element.
Syntax:
<button formenctype="value">Button Text</button>
Values:
- application/x-www-form-urlencoded: The default value. The form data is encoded as key-value pairs separated by & and spaces are replaced with + signs.
- multipart/form-data: Used for forms that include files or binary data. This encoding method sends each field as a separate part of the request.
- text/plain: The form data is sent as plain text with line breaks represented as literal newline characters.
Example:
<form action="/submit" method="post">
<label>Username:</label>
<input type="text" name="username">
<label>File:</label>
<input type="file" name="file">
<button type="submit" formenctype="multipart/form-data">Submit</button>
</form>
In this example, the formenctype="multipart/form-data" ensures that file uploads are handled correctly during form submission.
Browser Support:
The formenctype attribute is supported in all major browsers including Chrome, Firefox, Safari, Edge, and Opera.
Notes:
- Use
multipart/form-datawhen uploading files. - Use
application/x-www-form-urlencodedfor simple text-based form submissions. - Use
text/plainif you need to preserve formatting such as newlines in form data.
YouTip