{"id":6,"date":"2015-12-17T17:00:09","date_gmt":"2015-12-17T17:00:09","guid":{"rendered":"http:\/\/www.kenwalger.com\/blog\/?p=6"},"modified":"2017-07-09T22:50:52","modified_gmt":"2017-07-10T05:50:52","slug":"numeric-inputs-and-browser-differences","status":"publish","type":"post","link":"https:\/\/www.kenwalger.com\/blog\/css\/numeric-inputs-and-browser-differences\/","title":{"rendered":"Numeric Inputs and Browser Differences"},"content":{"rendered":"<p>I was working on a project the other day building a user information input form off of a mock design. Simple enough and then I got to an input requiring numbers for US Postal Codes. &#8220;Great!&#8221; I thought, &#8220;I can use an &lt;input type=&#8217;number&#8217;&gt; in my form.&#8221; Everything was spiffy until I tried it in various browsers. Let&#8217;s have a quick look at numeric inputs and browser differences.<\/p>\n<h3>Numeric Inputs<\/h3>\n<p>In Chrome, the form was rendered as:<\/p>\n<figure id=\"attachment_9\" aria-describedby=\"caption-attachment-9\" style=\"width: 76px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/no-spinner.png\" rel=\"attachment wp-att-9\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"9\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/css\/numeric-inputs-and-browser-differences\/attachment\/no-spinner\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/no-spinner.png?fit=76%2C48&amp;ssl=1\" data-orig-size=\"76,48\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"no-spinner\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Rendered in Chrome&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/no-spinner.png?fit=76%2C48&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/no-spinner.png?fit=76%2C48&amp;ssl=1\" class=\"size-full wp-image-9\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/no-spinner.png?resize=76%2C48\" alt=\"No spinner in Chrome!\" width=\"76\" height=\"48\" \/><\/a><figcaption id=\"caption-attachment-9\" class=\"wp-caption-text\">Chrome<\/figcaption><\/figure>\n<p>Looks pretty good, right? Nice and clean. Then I opened it in Firefox:<\/p>\n<figure id=\"attachment_10\" aria-describedby=\"caption-attachment-10\" style=\"width: 76px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/spinner.png\" rel=\"attachment wp-att-10\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"10\" data-permalink=\"https:\/\/www.kenwalger.com\/blog\/css\/numeric-inputs-and-browser-differences\/attachment\/spinner\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/spinner.png?fit=76%2C47&amp;ssl=1\" data-orig-size=\"76,47\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"spinner\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Rendered in Firefox&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/spinner.png?fit=76%2C47&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/spinner.png?fit=76%2C47&amp;ssl=1\" class=\"size-full wp-image-10\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/spinner.png?resize=76%2C47\" alt=\"Spinner for Firefox!\" width=\"76\" height=\"47\" \/><\/a><figcaption id=\"caption-attachment-10\" class=\"wp-caption-text\">Firefox<\/figcaption><\/figure>\n<p>What the heck? I didn&#8217;t add a number spinner in there. After digging around for a bit this is one of the wonderful side affects of a lack of specificity in the official <a href=\"http:\/\/www.w3.org\/html\/wg\/drafts\/html\/master\/semantics.html#number-state-%28type=number%29\" target=\"_blank\" rel=\"noopener noreferrer\">specification<\/a>. Further, if one continues to read through that particular specification (4.10.5.1.12 Number state (<em>type=number<\/em>)) one learns a couple of things.<\/p>\n<ol>\n<li>This specification does not define what user interface user agents are to use, and<\/li>\n<li>That it would be inappropriate for credit card numbers or US postal codes.<\/li>\n<\/ol>\n<p>Okay, so I choose the wrong type for my input field. But what is the deal with that spinner? What if I just want an actual number field but no spinner? Well, you smack it out of there with some CSS and the appearance property. If one uses:<\/p>\n<pre class=\" language-css\"><code class=\" language-css\"><span class=\"token comment\" spellcheck=\"true\">\/* Firefox - remove spinner *\/<\/span>\n<span class=\"token selector\">input[type=number] <\/span><span class=\"token punctuation\">{<\/span>\n  <span class=\"token property\">-moz-appearance<\/span><span class=\"token punctuation\">:<\/span> textfield<span class=\"token punctuation\">;<\/span>\n<span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p>The lovely spinner disappears. I won&#8217;t cover the rest of the browsers as they all are similar but slightly different.<\/p>\n<p>When then, do we use &lt;input type=&#8221;number&#8221;&gt;? Again, in looking at the specification, one would use it when one needs a number that is strictly speaking a number. It is also useful, with the spinner or not, if we want to limit the range and stepping of the number as follows:<\/p>\n<pre>&lt;input type=number min=0 step=0.01 name=price&gt;<\/pre>\n<h3><strong>Conclusion<\/strong><\/h3>\n<p>Another wonderful discovery of different renderings in different browsers. But, not that we know, we can allow our users to have the same experience in both browsers.<\/p>\n<p>Happy coding!<\/p>\n<p>&nbsp;<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6&#038;t=Numeric%20Inputs%20and%20Browser%20Differences&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Fi0.wp.com%2Fwww.kenwalger.com%2Fblog%2Fwp-content%2Fuploads%2F2015%2F12%2Fnumeric-inputs-e1493130075423.png%3Ffit%3D125%252C125%26ssl%3D1&#038;p&#091;title&#093;=Numeric%20Inputs%20and%20Browser%20Differences\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/facebook.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6&#038;text=Hey%20check%20this%20out\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/twitter.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6&#038;title=Numeric%20Inputs%20and%20Browser%20Differences\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/reddit.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6&#038;title=Numeric%20Inputs%20and%20Browser%20Differences\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px;margin-right:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/linkedin.png?resize=48%2C48&#038;ssl=1\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-48 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Numeric%20Inputs%20and%20Browser%20Differences&#038;body=Hey%20check%20this%20out:%20https%3A%2F%2Fwww.kenwalger.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F6\" style=\"font-size: 0px;width:48px;height:48px;margin:0;margin-bottom:5px\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"48\" height=\"48\" style=\"display: inline;width:48px;height:48px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/96x96\/mail.png?resize=48%2C48&#038;ssl=1\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>I was working on a project the other day building a user information input form off of a mock design. Simple enough and then I got to an input requiring numbers for US Postal Codes. &#8220;Great!&#8221; I thought, &#8220;I can use an &lt;input type=&#8217;number&#8217;&gt; in my form.&#8221; Everything was spiffy until I tried it in &hellip; <a href=\"https:\/\/www.kenwalger.com\/blog\/css\/numeric-inputs-and-browser-differences\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Numeric Inputs and Browser Differences&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":201,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pmpro_default_level":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[12,11,10,13],"yst_prominent_words":[229,231,226,232,227,237,236,223,233,224,228,225,235,230,234],"class_list":["post-6","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","tag-input","tag-number","tag-spinner","tag-type","pmpro-has-access"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.kenwalger.com\/blog\/wp-content\/uploads\/2015\/12\/numeric-inputs-e1493130075423.png?fit=125%2C125&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8lx70-6","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":5,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":444,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions\/444"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media\/201"}],"wp:attachment":[{"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/tags?post=6"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.kenwalger.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}