Ordinary closing tag and self closing tag in html [duplicate]

本小妞迷上赌 提交于 2020-01-17 02:41:08

问题


Can anyone tell about the Performance between ordinary closing tag and tag self tag in html?

<area />
<base />
<basefont />
<br />
<hr />
<input />
<img />
<link />
<meta />

I saw these from here(Using the XHTML closing slash (/) on normal tags?).

Actually My Main question is why we use this ?

I read the answer from :What's the difference between <tag></tag> and <tag /> in HTML?

the Answer is :

A self-closing tag has no children and no value for inner text (null):

Is it correct? Because We can write inner text in these fields

<input />
    <img />
    <link />

So I am still confusing. Please give me a clear answer.


回答1:


There is no such thing as a self-closing tag in HTML.

There are elements with mandatory start tags (<p>). There are elements with mandatory end tags (</script>).

There are elements with optional start tags (<body>). There are elements with optional end tags (</p>).

There are elements with forbidden end tags (<img>). (No element has a forbidden start tag).

HTML 5 allows a trailing / character in start tags for elements with forbidden end tags. This appears to be for the purposes of satisfying XML junkies and poor syntax highlighting software.

You cannot substitute a / for a real end tag. HTML parsers will tend to ignore end tags for elements with forbidden end tags. (However, for example, IIRC, </br> can produce odd results)


We can write inner text in these fields: <input /><img /><link />

You can't in HTML (or XHTML for that matter, they are defined as not being allowed child nodes).



来源:https://stackoverflow.com/questions/22452007/ordinary-closing-tag-and-self-closing-tag-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!