When I change the font-size CSS property of the <input type="number">
element, either directly with CSS or post-element creation via JavaScript, the spinners don’t change size in either FireFox or Safari. The input/display box does. So with larger fonts — extremely important for accessibility — the actual spinner buttons are relatively tiny when the font is large.
In FireFox:
According to Mozilla, checking this morning:
There is no standard way to change the style of spinners used to change the value of the field, with the spinners on Safari being outside the field.
This seems… unreasonable. It also seems unreasonable the spinner size doesn’t track the font size in use. I feel like I must be missing something.
Is my only option to completely roll my own spinner?
2
Answers
Yes, you need to create your own custom input element.
The browsers on those devices should be responsible to provide appropriate ways to change the number.
The browsers standard form elements (like
input
) are just very basic and un-styled, pretty much just like all HTML elements (e.g.h1
,p
,ul
, …) would have some basic default style if you would create an HTML page without any CSS.You can create an HTML page without any styling, including number inputs, and you might not like the style, but it will look consistent. If you zoom the whole page (usually
CTRL
+
/CTRL
-
/CTRL
mouse-wheel
), then the up- / down-buttons would as well scale to match the font size.The up- / down-buttons are no HTML elements themselves, but only a "convenience" addition that the browser provides. To satisfy the declaration
<input type="number">
the browser could theoretically decide to just render only the input box, or only some up- / down-buttons, or something else.This is even worse with e.g. a
<input type="file">
, which renders including a button and a file name, which can’t be styled with CSS.Turns out that making bigger controls for
input[type="number"]
is not a cross-browser feature. So one thing that you can do to make it work everywhere is "simulate" the controls.1- First hide the native controls
This can be done simply in CSS like this:
2- Next add 2 custom buttons with their actions
(Complete solution)
And for sure you can customize the buttons as you desire, you don’t have to follow the styles that I’ve used.
Regards