For <input type=number>
, by the HTML5 CR, the size
attribute is not allowed. However, in Obsolete features it says: “Authors should not, but may despite requirements to the contrary elsewhere in this specification, specify the maxlength and size attributes on input elements whose type attributes are in the Number state. One valid reason for using these attributes regardless is to help legacy user agents that do not support input elements with type="number" to still render the text field with a useful width.”
Thus, the size
attribute can be used, but it only affects older browsers that do not support type=number
, so that the element falls back to a simple text control, <input type=text>
.
The rationale behind this is that the browser is expected to provide a user interface that takes the other attributes into account, for good usability. As the implementations may vary, any size imposed by an author might mess things up. (This also applies to setting the width of the control in CSS.)
The conclusion is that you should use <input type=number>
in a more or less fluid setup that does not make any assumptions about the dimensions of the element.