Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

Possible Duplicate:
Space Before Closing Slash?

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?

like image 941
Deleted Avatar asked Oct 17 '25 05:10

Deleted


2 Answers

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

like image 179
Gordon Tucker Avatar answered Oct 19 '25 20:10

Gordon Tucker


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.

like image 35
Chuck Avatar answered Oct 19 '25 20:10

Chuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!