The size attribute is used to specify the number of visible options in a <select> dropdown list. It controls the height of the dropdown box.
- Defines how many options are visible at one time.
- Helps display multiple options without scrolling.
- Used to create list-style dropdown menus in forms.
Syntax:
<select size = "value"> option values...</select> Attribute Values: It contains a numeric value which specify the number of visible options in the drop-down list. It has a Default value which is 4.
Note: If the size attribute value is greater than 1 but less than the total number of options, the browser automatically displays a scrollbar to access additional options.
<!--Driver Code Starts-->
<!DOCTYPE html>
<html>
<head>
<title>HTML select size Attribute</title>
</head>
<!--Driver Code Ends-->
<body>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<h2>
HTML select size Attribute
</h2>
<p>Sorting Algorithms</p>
<select size="3">
<option value="merge">merge sort</option>
<option value="bubble">bubble sort</option>
<option value="selection">selection sort</option>
<option value="quick">quick sort</option>
<option value="insertion">insertion sort</option>
</select>
</body>
<!--Driver Code Starts-->
</html>
<!--Driver Code Ends-->