Select size attribute

Definition and Usage

size Attribute to set or return the size of the dropdown list Size attribute The value.

The size attribute specifies the number of visible options in the dropdown list.

Note:In Chrome and Safari, the size attribute may not work properly for size="2" and size="3".

See also:

HTML Reference Manual:HTML <select> size Attribute

HTML Reference Manual:HTML <select> Tag

Example

Example 1

Change the number of visible options in the dropdown list:

document.getElementById("mySelect").size = "4";

Try it yourself

Example 2

Return the number of visible options in the dropdown list:

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

Try it yourself

Syntax

Return the size attribute:

selectObject.size

Set the size attribute:

selectObject.size = number

Attribute Value

Value Description
number

Specifies the number of visible options in the dropdown list.

If the value is greater than 1 but less than the total number of options in the list, the browser will add a scrollbar to indicate that there are more options to view.

Technical Details

Return Value: Number, representing the number of visible options in the dropdown list.

Browser Support

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