What does enctype='multipart/form-data' mean in HTML?

Use the enctype attribute to specify how the browser encodes the data before it sends it to the server. Possible values are −

  • application/x-www-form-urlencoded − This is the standard method most forms use in simple scenarios.

  • mutlipart/form-data − This is used when you want to upload binary data in the form of files like image, word file etc.


Let us now see an example −

<!DOCTYPE html> <html> <head> <title>HTML enctype attribute</title> <style> form { width: 70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin: 5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <h1>Login</h1> <form enctype="multipart/form-data" action="" method="post"> <fieldset> <legend>Enter the login details</legend> <label for="EmailSelect">Email Id: <input type="email" id="EmailSelect"> <input type="button" onclick="getUserEmail('abc')" value="abc"> <input type="button" onclick="getUserEmail('pqr')" value="pqr"><br> <input type="button" onclick="login()" value="Login"> </label> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var inputEmail = document.getElementById("EmailSelect"); function getUserEmail(userName) { if (userName === 'abc') inputEmail.value = 'abc@MNC.com'; else inputEmail.value = 'pqr@MNC.com'; } function login() { if (inputEmail.value !== '') divDisplay.textContent = 'Successful Login. Hello ' + inputEmail.value.split("@")[0]; else divDisplay.textContent = 'Enter Email Id'; } </script> </body> </html>

Login and display the result −