{"id":198412,"date":"2015-03-25T06:28:19","date_gmt":"2015-03-25T13:28:19","guid":{"rendered":"http:\/\/css-tricks.com\/?p=198412"},"modified":"2015-03-26T08:51:56","modified_gmt":"2015-03-26T15:51:56","slug":"numeric-inputs-a-comparison-of-browser-defaults","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/numeric-inputs-a-comparison-of-browser-defaults\/","title":{"rendered":"Numeric Inputs – A Comparison of Browser Defaults"},"content":{"rendered":"
The spec, purposefully, stops short of telling implementations (browsers) how to handle UI. In this article we’re looking specifically at This specification does not define what user interface user agents are to use.<\/p><\/blockquote>\n It goes on to explain that different languages, cultures, and regions might have good reason to handle numeric inputs differently. So browsers are on their own here, and perhaps this time unsurprisingly, there are quite a few different approaches to the UI. Let’s take a look.<\/p>\n <\/p>\n This produces a simple form with one single input that accepts numeric values. I added some CSS for presentational purposes in the demos that follow, but this is the basic HTML markup we’re looking at.<\/p>\n Internet Explorer offers the simplest default presentation among desktop browsers. The input looks like any other form input that accepts text. In fact, IE is making no user interface decisions for us at all, except the ability to clear the input once something has been entered. That’s a handy little feature, and one that other browsers do not include (although it’s sometimes seen on Firefox introduces UI that IE does not: spinner controls. These controls include up and down arrows that increase and decrease the numeric value of the field when clicked, respectively.<\/p>\n Removing the controls can be accomplished with a little CSS using the While that does a nice job of removing the controls, it appears we have no control over the design of them.<\/p>\n Firefox and Safari are similar in how they treat numeric inputs. Both include spinner controls and both leave out the clearing UI seen in IE.<\/p>\n We can also remove the controls from Safari, but differently than Firefox using a method that tackles the Shadow DOM<\/a>:<\/p>\n Another element that we can style in the Shadow DOM is the invisible box around the number:<\/p>\n Might be useful, or it might not. Either way, it’s nice to have a little more design flexibility in Safari (and Chrome) compared to what we’ve seen so far.<\/p>\n Chrome sort of falls in the middle of the crowd. At first glance, we’re presented with a simple form input. Then, just as the cursor moves over the field, the same controls in Firefox and Safari are displayed.<\/p>\n Again, it’s interesting and worth noting that Firefox, Safari, Chrome and Opera have decided that quantity controls are enough of a benefit to user experience that they include them where IE has left them out. Then again, Chrome takes the middle ground by revealing the controls on hover as opposed to displaying them by default.<\/p>\n<input type=\"number\"><\/code>, and you might be surprised to learn that the spec specifically says<\/a>: <\/p>\n
The Markup<\/h3>\n
<form>\r\n <label for=\"age\">Enter your age<\/label>\r\n <input type=\"number\" id=\"age\" name=\"age\">\r\n<\/form><\/code><\/pre>\n
How Internet Explorer Handles It<\/h3>\n
type=\"search\"<\/code> inputs).<\/p>\n
How Firefox Handles It<\/h3>\n
appearance<\/code><\/a> property:<\/p>\n
\/* Remove controls from Firefox *\/\r\ninput[type=number] {\r\n -moz-appearance: textfield;\r\n}<\/code><\/pre>\n
How Safari Handles It<\/h3>\n
\/* Remove controls from Safari and Chrome *\/\r\ninput[type=number]::-webkit-inner-spin-button, \r\ninput[type=number]::-webkit-outer-spin-button { \r\n -webkit-appearance: none;\r\n margin: 0; \/* Removes leftover margin *\/\r\n}<\/code><\/pre>\n
\/* Adds a box around the numeric value in Safari and Chrome *\/\r\ninput[type=number]::-webkit-textfield-decoration-container {\r\n border: 1px #ccc solid;\r\n background: #efefef;\r\n}<\/code><\/pre>\n
How Chrome Handles It<\/h3>\n