catcode.com > Guide to HTML Forms > More About One-Line Input

More About One-Line Input

There are other attributes that set on an <input type="text"> element.

size and maxlength

The size attribute tells how many characters wide the input field should be. The maxlength attribute tells how many characters can be typed into a field. Try typing into the fields below. (To save space, we've left out the HTML for the <form> and send buttons.)

<input type="text" name="long"
   size="20" maxlength="18" />
 
<input type="text" name="short"
   size="10" maxlength="8" />
 

User interface hint: always make the size a little larger than your maxlength. The field won't look as cramped, and it will avoid horizontal scrolling with older browsers, which used proportional fonts in text fields.

value

Remember how we said that the value for the field was whatever the user types into it? Well, you can pre-set a field's value by using the value attribute. For example, if you know that most of your customers are in California, you could have an input text field like the one below. (Of course, those users not from California could edit the information.)

<input type="text" name="state"
   size="4" maxlength="2"
   value="CA" />