Is there any way to use placeholder on <input type=number>
?
I've just checked against the HTML5 spec for input where a type is number and it explicitly says that the placeholder attribute may not be used. I also had errors with http://validator.w3.org when I tried to validate html with an input type of number with a placeholder attribute. Looks like browsers may support this but it's not valid in the HTML5 spec.
@zachleat is correct, the placeholder
attribute is allowed in the latest HTML5 spec:
HTML 5.1 2nd Edition: forms, number-state-typenumber (see the bookkeeping section)
The following common input element content attributes apply to the element: autocomplete, list, max, min, placeholder, readonly, required, and step content attributes;
Here is the Placeholders section in the MDN Web Docs about <input type="number">
: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Placeholders
Sometimes it's helpful to offer an in-context hint as to what form the input data should take. This can be especially important if the page design doesn't offer descriptive labels for each
<input>
. This is where placeholders come in. A placeholder is a value that demonstrates the for thevalue
should take by presenting an example of a valid value, which is displayed inside the edit box when the element'svalue
is""
. Once data is entered into the box, the placeholder disappears; if the box is emptied, the placeholder reappears.
Using Placeholder: <input type="number" placeholder="10">
Using Min and Max Values: <input type="number" placeholder="10">
Using Value: <input type="number" value="10">
© 2022 - 2024 — McMap. All rights reserved.