开发者

Do we still need the space before the slash in <hr /> and others? [duplicate]

开发者 https://www.devze.com 2023-01-09 17:02 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Space Before Closing Slash?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

Space Before Closing Slash?

开发者_Python百科

Hi,

If I remember correctly we have it in the first place as some old version of Netscape choked if we didn't add the space (it would think the node never ended).

But is it really necessary today?


According to the HTML5 specs, void elements don't need the self closing / character.

Their exact phrasing is

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

They list void elements as area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

I may be understanding it wrong, but that seems like the following are all valid for html5

<hr>
<hr/>
<hr />

So it seems it really depends on the doctype you use


If you're serving valid XML with a correct content-type: application/xhtml+xml header, then no. If you're serving XHTML as HTML, then you should have it there, though most browsers nowadays can handle some very broken code, so it's only critical if you value having correct markup.


Highly doubt it. Modern browsers are getting quite robust when it comes to things like this.

I've never bothered to insert that extra space myself for quite some time. And frankly, I don't even use XHTML, so I stick to <br> without the self closing :)

0

精彩评论

暂无评论...
验证码 换一张
取 消