Blynn
Blynn

Reputation: 1411

HTML5 input form required

I'm trying to figure out if a html5 input using required needs to have the self closing tag or not.

<input id="email_input" type="email" class="mim-text-input" required>

versus

<input id="email_input" type="email" class="mim-text-input" required />

Upvotes: 0

Views: 198

Answers (3)

Sileno Brito
Sileno Brito

Reputation: 459

By default it is convention used:

<input/> or <input> </ input>, 

the reason is to indicate the end of the statement. A tag that has more content inside eg:

<textarea> content </ textarea>.

A tag that has no content in and often and is defined only by their attributes eg:

<input/>.
<input> without </ input>

Works, only in HTML5 when a tag that has more content inside, in other HTML previous works because the browser or framework fixes for you. As you can see in the generated source code.

Upvotes: 0

johnkavanagh
johnkavanagh

Reputation: 4664

You're OK on both accounts: both are valid.

In the HTML5 syntax specification it clearly shows inputs without the trailing slash.

However, either are valid. The trailing slash can be used and is still considered valid to allow for easier compatibility between xHTML/HTML4 developments.

You could always run your code through the W3 Validator to be absolutely sure.

All that said, however, there's no promise that browser default behaviors aren't effected differently based on syntax so it's very much a case of user beware.

Upvotes: 1

Mansfield
Mansfield

Reputation: 15140

According to the W3C validator, both of those options are valid HTML5.

enter image description here

Upvotes: 2

Related Questions