LEARNING OBJECTIVES โต
- Understand how the
sizeattribute controls the visible row count and presentation mode of<select>. - Differentiate between a single-selection listbox (
size="N") and a multi-selection listbox (multiple size="N"). - Analyze the difference between
<input size>(character width) and<select size>(row height). - Navigate mobile browser behaviors and responsive layout adaptations for scrollable listboxes.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine an elevator control console in a 50-story skyscraper:
+-------------------------------------------------------------+
| ELEVATOR CONSOLE |
| |
| Option A: Standard Dropdown (size="1") |
| [ Floor: Floor 14 v ]
| (Must tap to open the full list of 50 floors) |
| |
| Option B: Scrollable Listbox Viewport (size="6") |
| +---------------------------------------------------------+ |
| | Floor 12: Executive Suites | |
| | Floor 13: Technical Support | |
| | Floor 14: Engineering Labs |*| <-- Scrollbar
| | Floor 15: Data Center |#|
| | Floor 16: Legal & Compliance |#|
| | Floor 17: Human Resources | |
| +---------------------------------------------------------+ |
+-------------------------------------------------------------+
Instead of requiring the user to click and expand a floating popup window, Option B presents a fixed 6-row viewing window directly on the screen. Users can immediately see a cluster of neighboring choices and scroll smoothly through the rest of the list.
In HTML forms, the size attribute on <select> controls the height of this visible viewing window, converting a collapsed single-line dropdown into an expanded, scrollable Listbox widget.
Technical Deep Dive & Specifications
The Specification & Dimensioning Rules
On a <select> element, the size attribute specifies the number of visible options (rows) displayed in the viewport.
+-------------------------------------------------------------------------------+
| <select size="N"> BEHAVIOR MATRIX |
+-------------------------------------------------------------------------------+
Markup Presentation Mode Selection Capability
------------------------------------------------------------------------------
<select> Collapsed Dropdown Popup Single Item Only
<select size="1"> Collapsed Dropdown Popup Single Item Only
<select size="5"> Expanded Scrollable Listbox Single Item Only
<select multiple> Expanded Scrollable Listbox Multiple Items (default 4)
<select multiple size="8"> Expanded Scrollable Listbox Multiple Items (8 rows)
<input size> vs <select size>: A Critical Distinction
Do not confuse the size attribute on text inputs with the size attribute on select controls:
| Element | Attribute | Measurement Unit | Purpose |
|---|---|---|---|
<input type="text" size="20"> |
size |
Typographic character width (ch) |
Horizontal width |
<select size="5"> |
size |
Number of visible <option> rows |
Vertical viewport height |
The Single-Selection Listbox Pattern
When size > 1 is applied to a <select> without the multiple attribute:
- The element renders as an expanded rectangular list box.
- The user can only select one item at a time.
- Clicking any option immediately selects it without needing modifier keys.
- Arrow keys (Up / Down) scroll and update the active selection in real time.
This pattern is ideal for desktop dashboards where users need to rapidly browse through a list of database tables, log channels, or email folders with high visual density.
+------------------------------------+
| ๐ inbox_2026 |
| ๐ sent_mail |
| ๐ draft_proposals | <-- Single click selects 1 row
| ๐ archive_raw |#| <-- Vertical scrollbar
| ๐ spam_quarantine |
+------------------------------------+
Mobile Operating System Quirks
On mobile touchscreens (especially iOS Safari and mobile Chrome):
- Mobile browsers frequently override
<select size="N">and continue to render their native modal bottom sheets or spinning wheel pickers when tapped. - Because touch devices lack scrollbars on native form controls, fixed-size desktop listboxes do not translate 1:1 to mobile UI.
- If a custom scrollable list is mandatory on mobile, build a responsive radio/checkbox group or a CSS-overflow container.
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 66 (
<select ... size="6">): Specifies a visible height of exactly 6 rows. The 7th and 8th options are accessible via the native vertical scrollbar. - Single-Selection Behavior: Notice that the
multipleattribute is absent. Clicking any log channel immediately highlights only that channel. - Line 67 (
selected): Setsauth_serviceas the initial active row. - Lines 85โ90 (Script): Updates the connection status panel in real time as the user navigates through rows using arrow keys or mouse clicks.
Expected Browser Render Output
+-----------------------------------------------------------+
| Server Log Channel Stream |
| |
| Select Active Log Channel (size="6") |
| +-------------------------------------------------------+ |
| | > auth-service.production.log (1.2 MB/s) [SELECTED] | |
| | billing-api.production.log (450 KB/s) | |
| | payment-gateway.stripe.log (890 KB/s) |*| <-- Scrollbar
| | redis-cluster-cache.log (3.4 MB/s) |#|
| | worker-cron-daemon.log (120 KB/s) |#|
| | ingress-nginx-lb.log (15.8 MB/s) | |
| +-------------------------------------------------------+ |
| |
| Connected Stream: auth_service |
| [ Attach Live Tail ] |
+-----------------------------------------------------------+๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Build a High-Density Database Table Schema Inspector
Instructions:
- Create a database admin inspection form.
- Add a
<select id="table-inspector" name="table_name" size="5" required>listbox. - Populate the listbox with at least 8 database table names (e.g.,
users_v2,orders_2026,audit_events,products_inventory,sessions_cache,invoices_archive,api_tokens,webhooks_queue). - Pre-select
users_v2withselected. - Style the listbox with a fixed monospace font and responsive border styling.
- Test navigating the listbox purely using the keyboard (Tab to focus, Down Arrow / Up Arrow to cycle rows).
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Assuming
size="5"Enables Multiple Selection: Addingsize="5"does not allow multi-selection. It only sets the visible row height. To allow multi-selection, you must explicitly include themultipleattribute. - Forgetting Mobile Viewport Testing: Setting a large
size(e.g.,size="12") can blow out vertical layout space on mobile screens. Use CSS@mediaqueries to adjust heights responsively. - Confusing
<input size>with<select size>: On text inputs,sizesets character column width (width: N ch); on select elements,sizesets vertical row count (rows: N).
๐ก Pro Tips
- Default
sizeRules:- Standard
<select>: defaultsize="1"(popup dropdown). <select multiple>: defaultsize="4"(4-row listbox).
- Standard
- Scroll-Into-View on Focus: When users navigate long listboxes with keyboard arrow keys, browsers automatically scroll the active option into view inside the viewport.
๐ Key Takeaways
- The
sizeattribute on<select>specifies the number of visible rows rendered in the listbox. - Applying
size > 1withoutmultiplecreates a single-selection listbox where users pick one item by clicking directly. - The default
sizefor standard dropdowns is1; the default for<select multiple>is4. - Unlike text inputs where
sizecontrols character width,<select size>controls vertical option rows. - Mobile devices may override
sizein favor of full-screen touch pickers. - --