我需要“/”吗?在< img>的结尾处或< br>标签等? [英] Do I need a "/" at the end of an <img> or <br> tag, etc.?
问题描述
您是否需要在 img
标签末尾加入 /
?我在W3schools.com上看到了示例,没有 / :
< img src =smiley.gifalt =笑脸height =42 width =42>
我知道没有必要自动关闭标签,至少在我的浏览器中是这样,但我应该这样做吗?
/
XHTML&如果您使用HTML5文档类型,那么不需要以这种方式终止自闭合标签。 。
这适用于< img src =img.png/>
,< br />
,< hr />
等等。
即只要使用 Do you need to have a I know it isn't necessary to self-close the tag, at least in my browser, but should I do so? The If you're using a HTML5 doctype, then there's no need to terminate self-closing tags in this way. This applies to I.e. Just use If you need an empty element (like a 这篇关于我需要“/”吗?在< img>的结尾处或< br>标签等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!< img src =img.png>
,< br>
和<$ c $如果你需要一个空元素(比如 div $ c $> ),不要使用
< div />
,而应使用< div>< DIV>
。这很重要,因为在HTML5中,斜杠被忽略和< div />
被解释为< div>
/
at the end of an img
tag? I saw an example on W3schools.com without a /
:<img src="smiley.gif" alt="Smiley face" height="42" width="42">
/
is only required for XHTML & XML.<img src="img.png" />
, <br />
, <hr />
etc.<img src="img.png">
, <br>
and <hr>
.div
), don't use <div />
, instead use <div></div>
. This is important since in HTML5, the slash is ignored and <div />
is interpreted as <div>
without a closing tag.