So I have a rather random question but here we go. I am working on some trickery with Javascript for a plugin. Say I have an input that looks like this:
<input type='cc' id='cc' class='' />
Obviously the type cc
is not a valid input type. Does html automatically just default the unknown type to text
, or will it have an adverse effect?
Definition and Usage The <input type="text"> defines a single-line text field. The default width of the text field is 20 characters. Tip: Always add the <label> tag for best accessibility practices!
You can display default text within your web page form input box. The INPUT tag is used to create input fields within a web page form. When using HTML forms within a web page, many times you may need to display some ‘default text’ within your form to show your visitors what they should type in the form field.
Input Text Box Default Text. You can display default text within your web page form input box. The INPUT tag is used to create input fields within a web page form. When using HTML forms within a web page, many times you may need to display some ‘default text’ within your form to show your visitors what they should type in the form field.
Last Updated: 23-08-2019 The HTML <input> type Attribute is used to specify the type of <input> element to display. The default type of <input> type attribute is text.
Quoting directly from W3.org
An input element with no type attribute specified represents the same thing as an input element with its type attribute set to "text".
tl;dr: If you pass an invalid value for an enumerated attribute, it will use the invalid value default instead. If that doesn't exist, it will use the missing value default instead.
The input type
attribute doesn't define a invalid value default, but it defines a missing value default, which is text
.
Hence using an invalid value will default to text
.
From the WHATWG HTML spec:
2.4.3 Keywords and enumerated attributes
Some attributes are defined as taking one of a finite set of keywords. Such attributes are called enumerated attributes. [...] In addition, two default states can be given. The first is the invalid value default, the second is the missing value default.
[...]
If the attribute value matches none of the given keywords, but the attribute has an invalid value default, then the attribute represents that state. Otherwise, if the attribute value matches none of the keywords but there is a missing value default state defined, then that is the state represented by the attribute. Otherwise, there is no default, and invalid values mean that there is no state represented.
<input>
specifies a missing value default, which is text
:
The missing value default is the Text state.
If the value of the input type is not known or not supported in the browser, it'll default to "text".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With