๐ŸŽ›๏ธ Chapter 23: Selection & Choice Inputs

The size Attribute on select

Scrollable listbox presentation, fixed-row viewport dimensioning, single vs multi-choice ergonomics, and accessibility considerations.

LEARNING OBJECTIVES โŒต
  • Understand how the size attribute 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.
๐ŸŽฌ INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
๐ŸŒ
1. Input
Directives & Tags
โš™๏ธ
2. Parse
Tokenizer & AST
๐ŸŒณ
3. Layout
Box Model & Flow
๐ŸŽจ
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

๐Ÿ“– 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 multiple attribute is absent. Clicking any log channel immediately highlights only that channel.
  • Line 67 (selected): Sets auth_service as 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


SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...
+-----------------------------------------------------------+
| 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:

  1. Create a database admin inspection form.
  2. Add a <select id="table-inspector" name="table_name" size="5" required> listbox.
  3. 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).
  4. Pre-select users_v2 with selected.
  5. Style the listbox with a fixed monospace font and responsive border styling.
  6. Test navigating the listbox purely using the keyboard (Tab to focus, Down Arrow / Up Arrow to cycle rows).

๐Ÿ Starter Code Sandbox

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

โš ๏ธ Common Pitfalls

  1. Assuming size="5" Enables Multiple Selection: Adding size="5" does not allow multi-selection. It only sets the visible row height. To allow multi-selection, you must explicitly include the multiple attribute.
  2. Forgetting Mobile Viewport Testing: Setting a large size (e.g., size="12") can blow out vertical layout space on mobile screens. Use CSS @media queries to adjust heights responsively.
  3. Confusing <input size> with <select size>: On text inputs, size sets character column width (width: N ch); on select elements, size sets vertical row count (rows: N).

๐Ÿ’ก Pro Tips

  1. Default size Rules:
    • Standard <select>: default size="1" (popup dropdown).
    • <select multiple>: default size="4" (4-row listbox).
  2. 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 size attribute on <select> specifies the number of visible rows rendered in the listbox.
  • Applying size > 1 without multiple creates a single-selection listbox where users pick one item by clicking directly.
  • The default size for standard dropdowns is 1; the default for <select multiple> is 4.
  • Unlike text inputs where size controls character width, <select size> controls vertical option rows.
  • Mobile devices may override size in favor of full-screen touch pickers.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What presentation format does a browser render when given <select size="5"> (without the multiple attribute)?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

What is the default size value of an <input type="text"> vs a <select multiple>?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

If a <select size="4"> contains 10 child <option> tags, how do users view the remaining 6 options?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP