HTML - Text Fields

  »   HTML  »   HTML Tutorial - Text Fields Maxlength, Size, Value

Text fields are encountered as forms. Those are processed with the help of a programming language, most of the times ASP, PERL or PHP.

Additional attributes that are used for formatting the text fields are:

  • size - to set the field size
  • value - to set a predefined value
  • maxlength - to set the maximum caracters nunmber that can be entered by the user

We will exemplify each of them.

HTML - The text field size

The size attribute establishes the text field's length. The standard length of a text field is usually between 20-25 characters, but it can vary depending on the forms of the text field's purpose.

html<input type="text" size="5" /><br />

<input type="text" size="15" /><br />

<input type="text" size="25" />

Demo



HTML - Another attribute is value

Using this attribute we will make possible the writing of the information in our fields, information which the user can erase or not. This application is quite useful, especially when a PHP script recognizes a visitor and keeps the options chosen by the user.

html<input type="text" size="5" value="12345" /><br />

<input type="text" size="15" value="HTML text filed" /><br />

<input type="text" size="25" value="HTML Tutorials " />

Demo



HTML - Maxlength

Maxlength is one of the most useful attributes of the text fields because it does not allow the user to type a bigger number of characters than intended.

html<input type="text" size="5" maxlength="5" /><br />

<input type="text" size="15" maxlength="15" /><br />

<input type="text" size="25" maxlength="25" />

Demo



In case you want to introduce more than 5, 15, and 25 characters in the above fields, this thing will not be possible because of the restriction applied by 'maxlength'.