Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

will input default to a type of text?

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?

like image 421
Mark Hill Avatar asked Nov 10 '15 18:11

Mark Hill


People also ask

What is the default width of input type text?

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!

Can I display default text within my web page form input box?

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.

How do I display default text in a form?

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.

What is the default type of <input> type attribute?

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.


3 Answers

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".

enter image description here

like image 79
Tushar Avatar answered Oct 06 '22 00:10

Tushar


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.

like image 27
Felix Kling Avatar answered Oct 05 '22 23:10

Felix Kling


If the value of the input type is not known or not supported in the browser, it'll default to "text".

like image 20
manonthemat Avatar answered Oct 05 '22 23:10

manonthemat