Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Text size property

Input Text size property

Input Text Object Reference The Input Text object

Example

Set the size of the text field (in number of characters):

document.getElementById("myText").size = "50";

Try it »


Definition and Usage

The size property is used to set or return the size property value of the text field.

The size property sets or returns the size of the text field (in number of characters).

The default value is 20.

Tip: To set or return the number of characters allowed in a password field, use maxLength attribute.


Browser support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the size property


Syntax

Return the size property:

textObject

.size

Set the size property:

textObject

.size=

number

Attribute values

Value< Description
number Tracks the size of the text field, in characters. The default value is 20.

Technical details

Return Value: Number, representing the size of the text field, in characters

More examples

Example

Get the size of the text field:

var x = document.getElementById("myText").size;

x The output is:

30

Try it »


Related pages

HTML Reference Manual: HTML size property


Input Text Object Reference The Input Text object