[whatwg] Form input element for value-unit pairs

Christoph Päper christoph.paeper at crissov.de
Tue Mar 15 09:36:41 PDT 2011

Jukka K. Korpela:
> Christoph Päper wrote:
>>  <input type="number" id="fontsize" value="12" unit="pt">
> Or do you mean that the presence of the unit="..." attribute would trigger a special implementation of numeric input, so that the user is expected to enter both a number and a unit, with the latter defaulted according to the unit attribute?


UIs may autoconvert the value if the unit changes or keep it. I’m not sure which solution is better.

> Although the need for number & unit input is relatively common, I think it can quite satisfactorily be handled using a number input field and e.g. a dropdown menu of units accepted by an application (or maybe a textfield). After all, processing of the form data would most probably want to split a combined number & unit data item into its components, so why put them together in the first place?


Maybe it would work better with ‘datalist’:

  <input name=fontsize type=number unit=typo>
  <datalist id=typo>
    <option value=2.835 label=pt>
    <option value=1 label=mm>


  <input name=fontsize type=number unit=#typo>
  <datalist id=typo>
    <option value=pt label=point>
    <option value=mm label=millimetre>

More information about the whatwg mailing list