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.
Syntax
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.
Values
Attribute Values
One value type — a positive integer — with different meanings per element:
size="4" shows four rows so multi-select is obvious.
selected can pre-check defaults (see the selected attribute).
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.
Compatibility
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 ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetModern
Full support
Internet ExplorerLegacy support
Supported
sizeWidely supported
Bottom line: Safe for simple HTML demos. Prefer CSS for production layout; use maxlength when you need a real character cap.
Remember
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.