Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 input with multiple type attributes

Tags:

html

Our form software outputs all elements with 'type="text"', but I'd rather take advantage of the new types in HTML5, such as 'email', 'number', etc.

I can add these in at the end but I end up with multiple type attributes, eg:

<input type="text" name="email" type="email">

If there is more than one 'type' attribute present for an element, which is used - the first or last? And is it valid to have more than one? I'd guess not but trying to get round this situation...

like image 702
neil Avatar asked Sep 17 '25 09:09

neil


1 Answers

No you cannot, that will be an invalid HTML, you can safely use type="email" instead of type="text", because if browser is not HTML5 capable, it will treat any unknown type attribute value as text

And if you state something like this

<input type="text" type="email" />

Browser won't respect type="email"

Test Case

<!DOCTYPE html>
<form>
<input type="text" type="email" />
    <input type="submit" value="test" />
</form>

Remove type="text" attribute and browser will respect type="email"

like image 170
Mr. Alien Avatar answered Sep 20 '25 01:09

Mr. Alien