HTML input Tag formenctype Attribute Tutorial

In this section, we will learn what the formenctyp is and how to use it.

What is formenctype Attribute in HTML <input> Tag?

For security reasons, sometimes we need to encode the data that we send from a form on a webpage to a server.

In <input> elements of type image or submit, we can use the formenctype attribute to encode data of the form before being sent to a server.

There are different types of encoding algorithm and hence multiple values for the formenctype attribute.

Note: use this attribute only when the HTTP method used for that form is set to POST.

HTML formenctype Attribute in <input> Tag Syntax:

<input type = “image | submit” formenctype = “value”>

<input> Tag formenctype Attribute Values

In the list below you can see the values that could be used for the formenctype attribute:

Name

Description

application/x-www-form-urlencoded

This is the default value and when used, all the character of the form data will be encoded before being sent.

multipart/form-data

If in the form we have file as well (<input type= “file”>), this is the value that should be set for the formenctype attribute.

text/plain

If we use this value, it means the form data should not be encoded! For security reasons, this is not recommended at all.

Example: using formenctype attribute in HTML <input> tag

See the Pen using formenctype attribute in HTML <input> tag by Omid Dehghan (@odehghan) on CodePen.

Leave a Reply