Skip to content
Related Articles

Related Articles

Why does password boxes are smaller than text boxes in IE ?
  • Difficulty Level : Expert
  • Last Updated : 23 Jun, 2020

According to Microsoft, whenever Internet Explorer provides the HTML page structure, it uses the wrong character set even after providing the correct character set by the META tag.

HTML part of user input: The following HTML code shows the general password input form which works fine in Google Chrome, Firefox, Microsoft Edge but not in IE. The widths of the input boxes are different in case of IE even if we are specifying “ charset=’UTF-8′ “.




<!DOCTYPE html>
<html>
  
<head>
  <meta charset="UTF-8">
  <title>GeeksforGeeks</title>
</head>
  
<body>
  <form>
    <p>
      <label>TEXT INPUT:</label>
      <br>
      <input type="text">
      <br>
      <label>PASSWORD INPUT:</label>
      <br>
      <input type="password">
    </p>
  </form>
</body>
  
</html>

Note: The causes for this abnormal behavior of IE are specified in the documentation with the link below.
https://support.microsoft.com/en-us/help/928847/internet-explorer-uses-the-wrong-character-set-when-it-renders-an-html

Solution: It is known that there is some issue with the IE’s default character set.
Let us look into some solutions which are used to overcome this problem.

  1. Solution using jQuery: The jQuery code is included in the page load. Make equal-width of text and password input control boxes using jQuery.






    <!DOCTYPE html>
    <html>
      
    <head>
      <meta charset="UTF-8">
      <title>GeeksforGeeks</title>
      
      <script src=
        integrity=
    "sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
        crossorigin="anonymous">
      </script>
        
      <script type="text/javascript">
        $(document).ready(function () {
          $("input[type='text']").height(
            $("input[type='password']").height());
      
          $("input[type='text']").width(
            $("input[type='password']").width());
        });
      </script>
    </head>
      
    <body>
      <form>
        <p>
          <label>TEXT INPUT:</label>
          <br>
          <input type="text">
          <br>
          <label>PASSWORD INPUT:</label>
          <br>
          <input type="password">
        </p>
      </form>
    </body>
      
    </html>

    or




    <!DOCTYPE html>
    <html>
      
    <head>
      <meta charset="UTF-8">
      <title>GeeksforGeeks</title>
      
      <script src=
        integrity=
    "sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
        crossorigin="anonymous">
      </script>
        
      <script type="text/javascript">
        $(document).ready(function () {
          $("input[type='password']").height(
            $("input[type='text']").height());
      
          $("input[type='password']").width(
            $("input[type='text']").width());
        });
      </script>
    </head>
      
    <body>
      <form>
        <p>
          <label>TEXT INPUT:</label>
          <br>
          <input type="text">
          <br>
          <label>PASSWORD INPUT:</label>
          <br>
          <input type="password">
        </p>
      </form>
    </body>
      
    </html>
  2. Solution using CSS: Fix the width of both the input controls to some value depending on your project. Here “14em” width is used, just change this to the value of desired width.




    <!DOCTYPE html>
    <html>
      
    <head>
      <meta charset="UTF-8">
      <title>GeeksforGeeks</title>
      <style type="text/css">
        input {
          width: 14em;
        }
      </style>
    </head>
      
    <body>
      <form>
        <p>
          <label>TEXT INPUT:</label>
          <br>
          <input type="text">
          <br>
          <label>PASSWORD INPUT:</label>
          <br>
          <input type="password">
        </p>
      </form>
    </body>
      
    </html>
  3. By setting the default font family for inputs: (Most liked solution) This method uses same font family for all the inputs.




    <!DOCTYPE html>
    <html>
      
    <head>
      <meta charset="UTF-8">
      <title>GeeksforGeeks</title>
      <style type="text/css">
        input {
          font-family: sans-serif;
        }
      </style>
    </head>
      
    <body>
      <form>
        <p>
          <label>TEXT INPUT:</label>
          <br>
          <input type="text">
          <br>
          <label>PASSWORD INPUT:</label>
          <br>
          <input type="password">
        </p>
      </form>
    </body>
      
    </html>

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :