Input Text size attribute

Definition and Usage

size Set or return the value of the size attribute of the text field.

The HTML size attribute specifies the width of a text field (in characters), with a default value of 20.

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

See also:

HTML Reference Manual:HTML <input> size Attribute

Example

Example 1

Set the width of the text field:

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

Try it yourself

Example 2

Get the width of the text field:

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

Try it yourself

Syntax

Return the size attribute:

textObject.size

Set the size attribute:

textObject.size = number

Attribute Value

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

Technical Details

Return Value: A number representing the width of a text field, in characters.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support