Open In App

HTML formenctype Attribute

Last Updated : 15 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML formenctype Attribute is used in <button> and <input> tag with type “image” and “submit”. This attribute is used to specify that the form-data must be encoded when data sent to the server. It overrides the feature of the enctype attribute of the <form> element. 

Basically there are three types to encode the form-data which are given below- 

  • application/x-www-form-urlencoded: It is the default value. It encodes all the characters before sent to the server. It converts spaces into + symbols and special character into its hex value.
  • multipart/form-data: It is used to encode the file upload controls. This value does not encode any character. we can not upload images and file without using this encoding type.
  • text/plain: This value convert spaces into + symbols but special characters are not converted.

Syntax

<element formenctype="value">

Example: Below code demonstrates the use of formenctype attribute with two submit Button. one is set to default encoding type and the other is set to multipart form-data.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML Formenctype Attribute
    </title>
</head>
 
<body>
    <center>
        <h2>GeeksForGeeks</h2>
 
        <h2>HTML Formenctype Attribute</h2>
 
        <form action="#">
            <label>First Name:<input type="text"></label><br>
            <label>last Name:<input type="text"></label><br>
            <label>Address:<input type="text"></label><br>
            <input type="submit"
                value="submit with default encoding type">
            <button type="submit" formenctype="multipart/form-data">
                Submit as multipart form-data
            </button>
        </form>
    </center>
</body>
 
</html>


 Output:

 

 Supported Browsers: 

  • Google Chrome
  • Apple Safari
  • Firefox
  • Internet Explorer
  • Opera


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads