HTML size Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

Introduction

The size attribute controls how much of a form control is visible before scrolling. On <select>, it sets the number of visible option rows in a list box. On text-like <input> elements, it sets the approximate width in characters. It is not the same as the responsive sizes attribute on <img> or deprecated <font size> markup.

What You’ll Learn

01

<select>

Visible rows.

02

<input>

Char width.

03

List box

size > 1.

04

vs sizes

Different attr.

05

JavaScript

.size property.

06

CSS width

Modern layout.

Purpose of size

The purpose of the size attribute is to give authors a simple HTML-level control over how much of a form field is shown. For a <select>, a higher size turns the control from a compact dropdown into a scrollable list box that displays multiple options at once—useful for picking from long lists without opening a menu.

For <input type="text"> and similar types, size hints how many characters wide the field should appear. Browsers approximate this using the current font; for precise layout, CSS width is usually better.

💡
Not font size or responsive images

size on forms is unrelated to text font size or the sizes attribute used with srcset on images. Those are separate features with similar names.

📝 Syntax

Set size to a positive integer on <select> or supported <input> types:

size.html
<!-- List box: 5 visible rows -->
<select size="5">...</select>

<!-- Text input ~30 characters wide -->
<input type="text" size="30">

Syntax Rules

  • Value is a non-negative integer (typically 1 or greater).
  • On <select>: default is 1 (dropdown). Values > 1 show a list box.
  • On <input>: applies to text, search, tel, url, email, and password.
  • Default input width is often 20 characters if size is omitted.
  • Does not limit how many characters the user can type—only visible width.
  • Pair list boxes with <label> and consider multiple for multi-select lists.

💎 Values

The size attribute accepts an integer. Meaning depends on the element:

  • size="1" on <select> — Standard single-line dropdown (default).
  • size="5" on <select> — List box showing five option rows at once.
  • size="20" on <input type="text"> — Field roughly 20 characters wide.
  • size="50" on <input type="email"> — Wider email field hint.
size-values.html
<select size="4" multiple>
  <option>Red</option>
  <option>Green</option>
  <option>Blue</option>
  <option>Yellow</option>
  <option>Purple</option>
</select>

⚡ Quick Reference

Elementsize meaningExample
<select>Visible option rowssize="5"
<input type="text">Width in characterssize="30"
<input type="email">Width in characterssize="40"
Default select1 (dropdown)Collapsed menu
JavaScriptelement.size = nDynamic update
Not for<img sizes>Different attribute

Applicable Elements

ElementSupported?Notes
<select>YesVisible rows in list box mode
<input type="text">YesCharacter width hint
<input type="email">, etc.Yessearch, tel, url, password
<input type="number">NoUse CSS width instead
<textarea>NoUse rows and cols
<img>NoUse sizes with srcset (different attribute)

size vs sizes vs CSS width

FeaturesizesizesCSS width
Used onselect, inputimg, sourceAny element
PurposeVisible rows or char widthResponsive image slot sizesExact layout sizing
UnitInteger countMedia condition listpx, %, rem, etc.
Use today?Yes for formsYes for imagesPreferred for precise UI

Examples Gallery

select list box with five visible rows, input character width, and dynamic element.size in JavaScript.

👀 Live Preview

<select size="4"> showing four visible options:

Six options exist, but only four rows are visible without scrolling inside the list box.

Example — select List Box

Display five options at once in a scrollable list:

size.html
<select size="5">
  <option value="option1">Option 1</option>
  <option value="option2">Option 2</option>
  <option value="option3">Option 3</option>
  <option value="option4">Option 4</option>
  <option value="option5">Option 5</option>
  <option value="option6">Option 6</option>
</select>
Try It Yourself

How It Works

With size="5", the browser renders a list box instead of a collapsed dropdown. Users see five options immediately and scroll for the rest.

Example — input Character Width

Set visible width on a text field with size:

input-size.html
<label for="username">Username:</label>
<input type="text" id="username" name="username" size="30">
Try It Yourself

How It Works

size="30" is a hint to the browser about display width. It does not set maxlength—add maxlength separately if you need to cap input length.

Dynamic Values with JavaScript

Adjust visible rows at runtime with the size property:

dynamic-size.html
<select id="dynamicSelect">
  <option>Option 1</option>
  <option>Option 2</option>
  <option>Option 3</option>
  <option>Option 4</option>
</select>

<script>
  document.getElementById("dynamicSelect").size = 3;
</script>
Try It Yourself

How It Works

HTMLSelectElement.size and HTMLInputElement.size reflect the attribute. Update them when expanding or collapsing option lists based on user actions.

♿ Accessibility

  • Label every control — List boxes and inputs need <label for="..."> associations.
  • Do not rely on size alone — A tiny list box can hide options from sighted users; ensure scrolling is obvious.
  • Avoid overwhelming list boxes — Very large size values on long lists can clutter the page; consider search/filter UI.
  • Keyboard support — Native <select> list boxes support arrow keys; custom widgets need equivalent behavior.
  • Mobile layouts — Test list boxes on small screens; CSS width often works better than large character counts.

🧠 How size Works

1

Author sets size integer

On select or input.

Markup
2

Browser sizes control

Rows or char width.

Rendering
3

User interacts

Scroll or type freely.

UX
=

Clearer form layout

Right-sized visible area.

Browser Support

The size attribute on <select> and text-like <input> elements is supported in all modern browsers.

HTML5 · Fully supported

Universal form sizing

All major browsers honor size on select and supported input types.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
size attribute 99% supported

Bottom line: Use size on forms confidently; combine with CSS for responsive layouts.

💡 Best Practices

✅ Do

  • Use size > 1 on <select> when showing many options at once helps
  • Set reasonable size on inputs to match expected content length
  • Combine with maxlength when you need to limit typed characters
  • Use CSS width for responsive, pixel-perfect layouts
  • Label list boxes clearly for screen reader users

❌ Don’t

  • Confuse size with sizes on images
  • Use size on <textarea> (use rows/cols)
  • Assume size limits how much users can type or select
  • Set excessively large list boxes that dominate the page
  • Rely on deprecated <font size> for text styling

Conclusion

The size attribute is a practical tool for controlling visible form control dimensions in HTML. On <select>, it defines list box height; on text inputs, it hints character width.

Use it to improve form usability, but remember it is not a substitute for maxlength, CSS layout, or the unrelated sizes attribute on responsive images. Test across devices to keep controls comfortable for every user.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about size

Bookmark these before sizing your next form.

5
Core concepts
02

input width

In characters

input
📄 03

List box

size > 1

Behavior
⚙️ 04

.size JS

Dynamic update

Dynamic
📸 05

Not sizes

Images differ

Compare

❓ Frequently Asked Questions

On <select>, it sets visible option rows in a list box. On text-like <input> elements, it sets approximate character width.
<select> and <input> types including text, search, tel, url, email, and password.
The select renders as a list box showing five option rows at once. Extra options scroll inside the control.
No. size controls visible width. maxlength limits how many characters can be entered.
Yes. Set element.size = 3 on select or input elements using the reflected IDL property.
Yes in all modern browsers on supported form elements.

Size form controls the right way

Practice select size list boxes and input size width in the Try It editor.

Try select list box →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful