HTML size Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The size attribute sets a visible size hint for form controls. On <input>, it is roughly how many characters wide the field looks. On <select>, it is how many options are shown at once.

The value must be a valid integer greater than zero. It does not validate input length — use maxlength for that. Do not confuse it with sizes on responsive images.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers for input and select.

CSS can override size.

MDN: if CSS sets width (or otherwise changes layout), CSS wins. Prefer CSS for precise layouts; use size as a simple HTML hint.

HTML Syntax

syntax.html
<input type="text" size=" number">
<select size=" number">…</select>

number is an integer > 0. Invalid or missing values fall back to the browser default control size.

Attribute Values

One value type — a positive integer — with different meanings per element:

UseDescriptionTry it
input size="n"Visible width hint (~n characters)Try it
select size="n"Show about n options (list box height)Try it
With multipleCommon for multi-select list boxesTry it
Omitted / invalidBrowser default width / closed dropdownTry it

Live Preview

Switch between input and select, then change size to see width vs visible rows.

control

No extra CSS width here — so the HTML size hint is easier to see.

Demo

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Text Input Visible Width

Make a short field look shorter than a long one — without capping typed length.

HTML
<label for="zip">ZIP code:</label>
<input type="text" id="zip" name="zip" size="10">

<label for="city">City:</label>
<input type="text" id="city" name="city" size="30">
Try It Yourself

How It Works

  1. size="10" hints a narrower field for ZIP.
  2. size="30" hints a wider field for city names.
  3. Not a length limit — users can still type more than 10/30 characters unless you add maxlength.
  4. Label each control with matching for / id.

Example 2 — Select Visible Options

Show several choices at once instead of a closed dropdown.

HTML
<label for="fruit">Favorite fruit:</label>
<select id="fruit" name="fruit" size="3">
  <option>Orange</option>
  <option>Banana</option>
  <option>Apple</option>
  <option>Mango</option>
</select>
Try It Yourself

How It Works

  1. size="3" asks the browser to show about three options.
  2. List box look — usually no closed dropdown arrow UI.
  3. Still single-select unless you also set multiple.
  4. Scroll appears if there are more options than size.

Example 3 — size with multiple

A multi-select list box with several rows visible.

HTML
<label for="langs">Languages:</label>
<select id="langs" name="langs" multiple size="4">
  <option value="html" selected>HTML</option>
  <option value="css" selected>CSS</option>
  <option value="js">JavaScript</option>
  <option value="py">Python</option>
</select>
Try It Yourself

How It Works

  1. multiple allows more than one selected option.
  2. size="4" shows four rows so multi-select is obvious.
  3. selected can pre-check defaults (see the selected attribute).
  4. Teach users how to multi-select on their OS (Ctrl/Cmd or Shift click).

Edge Cases & Pitfalls

Most confusion mixes display size with validation limits or responsive image attributes.

limits

size ≠ maxlength

size changes how wide or tall the control looks. maxlength caps typed characters. You often need both.

images

size ≠ sizes

sizes is for responsive <img> / srcset. Completely different attribute.

css

Stylesheets override layout

A CSS width on the input will ignore the visual effect of size. Use one approach consistently.

value

Must be > 0

MDN requires a non-negative integer greater than zero. Zero or invalid values are ignored.

validation

No constraint validation

size does not make a field required or limit submitted data. Pair with proper validation attributes and server checks.

Browser Support

size is an HTML attribute on input and select. Exact character-to-pixel width can vary by font and UA.

✓ Baseline · Widely available

size

Widely supported across modern browsers. Treat character width as a hint — CSS is more precise for layouts.

98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet Modern
Full support
Internet Explorer Legacy support
Supported
size Widely supported

Bottom line: Safe for simple HTML demos. Prefer CSS for production layout; use maxlength when you need a real character cap.

Key Takeaways

  • input: visible width hint in characters.
  • select: how many options are visible.
  • Not validation: use maxlength / other constraints for limits.
  • CSS wins when width/layout styles are applied.

One line: size changes how big the control looks — not how much data is allowed.

Frequently Asked Questions

On input, size is a hint for how many characters wide the field looks while editing. On select, size is how many options are visible (the list height). It must be an integer greater than zero.
Primarily input (text-like types) and select. It is not the same as the sizes attribute used with img/srcset.
No. size affects visible width (input) or visible rows (select). maxlength caps how many characters the user can type.
No. MDN: size has no impact on constraint validation. Use maxlength, required, pattern, and server checks for validation.
If CSS targets the element with properties that change width (or height for select layouts), CSS takes precedence over the size attribute.
The control usually shows as a list box instead of a closed dropdown, displaying that many options at once. Often paired with multiple for multi-select UIs.

Next: sizes

Tell the browser how wide responsive images will display.

sizes tutorial →

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.

8 people found this page helpful