简体   繁体   中英

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 />

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

在此处输入图片说明

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM