Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

What is formenctype Attribute in HTML Form ?

  • Last Updated : 22 Oct, 2021

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 input type submitand input type image“. 

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

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 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 files without using this encoding type.
  • text/plain: This value converts spaces into + symbols but special characters are not converted.

Example: 

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:




My Personal Notes arrow_drop_up
Recommended Articles
Page :