23

I want to use the html5 element <input type="number"> on my website, but i want to know what happens to this field in browsers that do not support this feature? Is it than a classic <input type="text"> field for those browsers?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Torben
  • 5,388
  • 12
  • 46
  • 78
  • 4
    you could always just try it and see – Muad'Dib May 09 '12 at 17:54
  • Torben, did one of the posts below answer your question? If so, could you accept it? (See [How do I ask a question here?](http://stackoverflow.com/faq#howtoask) in the FAQ.) If not, what additional information do you require that isn't provided below? – 0b10011 Jun 28 '12 at 20:09

3 Answers3

29

When a browser does not recognize a particular type value for an <input>, it reverts to it's default value, which is text. So, all of the following are equivalent on browsers that do not support type="number":

<input type="number">
<input type="somevaluethatdoesntexist">
<input type="text">
<input>

For browsers that do support type="number", the number <input> will be displayed instead of the text <input>.

Read more about the type attribute in the HTML Specification.

0b10011
  • 18,397
  • 4
  • 65
  • 86
5

Refer to

Open this Example on IE and Chrome and see the difference.

Supported Browsers:

  • Opera
  • Safari
  • Chrome

If HTML 5 Input Types are not supported on a browser, they will behave as regular text fields.

Donald Byrd
  • 7,668
  • 4
  • 33
  • 50
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • 4
    If you're going to specify W3C, link to the spec, **not** w3schools.com (which has *no* affiliation). – 0b10011 May 09 '12 at 18:00
  • 1
    This war against W3Schools has to stop. So what if they're not affiliated with W3C? A bunch of answers/comments etc mention random forums, blogs and pretty much any kind of site, and they're not voted down. Then we see people voting down solely based on the fact that there's a link to W3schools, even tho its a valid answer.. – MilkyWayJoe May 09 '12 at 18:55
  • @MilkyWayJoe, first off, a lot of the time W3Schools is voted down because the particular page linked to **has invalid information**. In this case, Siva had "W3C - HTML 5 Input Types" linked to W3Schools, which is incorrect information as W3C and W3Schools are not affiliated (so I voted down to avoid confusion, not just because W3Schools was linked to, which I have removed because the answer has been updated accordingly). However, there *are* some people who vote down W3Schools solely because it's W3Schools, which I don't agree with, but this was not the case for this answer. – 0b10011 May 09 '12 at 19:03
2

Caution, while older browsers ignore and default to "text", many newer browsers simply do the wrong thing. See: What models of Samsung smartphones have missing period for html5 input type="number"?

Community
  • 1
  • 1
maxweber
  • 576
  • 1
  • 5
  • 12