The size attribute of the input specifies the visible width of the input field in terms of characters.
By default, the size is set to 20 characters.
Example
Define the width of an input field:
<form> <label for=”fname”>First name:</label><br> <input type=”text” id=”fname” name=”fname” size=”50″><br> <label for=”pin”>PIN:</label><br> <input type=”text” id=”pin” name=”pin” size=”4″> </form> |
The input maxlength attribute sets the maximum character limit allowed in an input field.
Please note: When maxlength is defined, the input field restricts the entry to the specified character count. However, it doesn’t offer any visual feedback. Therefore, if you wish to notify the user, you’ll need to implement JavaScript code.
Example
Establish a maximum character limit for an input field:
<form> <label for=”fname”>First name:</label><br> <input type=”text” id=”fname” name=”fname” size=”50″><br> <label for=”pin”>PIN:</label><br> <input type=”text” id=”pin” name=”pin” maxlength=”4″ size=”4″> </form> |