Easy Tutorial
❮ Event Key Location Prop Meta Content ❯

size Attribute

Input Text Object

Example

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

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

Definition and Usage

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

The size attribute 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 the maxLength attribute.


Browser Support

All major browsers support the size attribute.


Syntax

Return the size attribute:

Set the size attribute:

Attribute Values

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

Technical Details

| Return Value: | A 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 outputs:

30

Related Pages

HTML Reference: HTML <input> size Attribute


❮ Event Key Location Prop Meta Content ❯