Input Search maxLength Attribute

Definition and Usage

maxLength Set or return the value of the maxLength attribute of the search field.

The HTML maxLength attribute specifies the maximum number of characters allowed in the search field, with a default value of 524288.

Tip:To set or return the width of the search field (in characters), use size attribute.

See also:

HTML Reference Manual:HTML <input> maxlength Attribute

Example

Example 1

Get the maximum number of characters allowed in a specific search field:

var x = document.getElementById("mySearch").maxLength;

Try it yourself

Example 2

Change the maximum number of characters allowed in the search field:

document.getElementById("mySearch").maxLength = "8";

Try it yourself

Syntax

Return maxLength attribute:

searchObject.maxLength

Set maxLength attribute:

searchObject.maxLength = number

Attribute Value

Value Description
number Specifies the maximum number of characters allowed in the search field. The default value is 524288.

Technical Details

Return Value: Number, representing the maximum number of characters allowed in the search field.

Browser Support

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