问题
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