Open In App

What is formenctype Attribute in HTML Form ?

Last Updated : 16 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML formenctype attribute is used to specify the type of encoding to be used when submitting the form. It defines how the form data should be encoded when it is sent to the server. 

It works with the input type submitand input type image“. 

The formenctype attribute is used when there are multiple submit buttons inside the form. It is used to override the feature of the enctype attribute of the <form> element.

Syntax:

<element_name formenctype=”application/x-www-form-urlencoded/multipart/form-data/text/plain”>

Basically, there are ways to be used to encode the form data.

  • application/x-www-form-urlencoded: It is the default value. It encodes all the characters before being sent to the server. It converts spaces into + symbols and special characters into their 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 files without using this encoding type.
  • text/plain: This value converts spaces into + symbols but special characters are not converted.

Example: in this example, we are using formenctype attribute.

HTML




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <h2 style="color:green">
            GeeksforGeeks
        </h2>
        <p>
            <b>
                What is formenctype attribute in HTML form?
            </b>
        </p>
        <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><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:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads