You are not logged in.

#1 2011-09-18 13:02:51

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

[Solved] HTML5 - do I need to close void tags?

http://w3schools.com/html5/tag_hr.asp

It's about HTML5, they use <hr /> in an example but <hr> below the example. So it's uncertainty for those who tend to follow standards. When it's about HTML5 as it is - which way is more correct - to always use closing tag or not to use it in tags such as <hr> and <br>?

Last edited by Mr. Alex (2011-09-18 17:09:20)

Offline

#2 2011-09-18 13:17:34

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] HTML5 - do I need to close void tags?

You mean

The <hr> tag creates a horizontal line in an HTML page.

- I think it's just the way they call tags.


Edit: Ah, no, the page code shows

<p>The &lt;hr&gt; tag is supported in all major browsers.</p>
<hr>

<h2>Definition and Usage</h2>

Edit2: Hmm, I get the above piece of code when using 'View selection source' from Firefox' context menu, but when viewing the whole page source, it shows

<p>The &lt;hr&gt; tag is supported in all major browsers.</p>
<hr />

<h2>Definition and Usage</h2>

Edit3: http://www.html-5.com/tags/hr-tag/index.html

Since the <hr/> tag is a void element, it is not allowed to have any content, even HTML comments and therefore should always be coded as a self-closing standalone tag, ending with the delimiters /> rather than just > (<hr/>).

Last edited by karol (2011-09-18 13:31:53)

Offline

#3 2011-09-18 13:54:17

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [Solved] HTML5 - do I need to close void tags?


This silver ladybug at line 28...

Offline

#4 2011-09-18 15:17:24

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

Re: [Solved] HTML5 - do I need to close void tags?

lolilolicon, yeah, it says pretty definitely:

Void elements only have a start tag; end tags must not be specified for void elements.
...
A non-void element must have an end tag...

karol, thanks but link you posted seems not to be official site whereas dev.w3.org is official. So I guess we don't need to close <hr>, <br> and other void tags.

Offline

#5 2011-09-18 15:32:11

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [Solved] HTML5 - do I need to close void tags?

Mr. Alex, I think you might have misunderstood it -- <hr/> is a start tag:

w3.org wrote:

start tags consist of the following parts, in exactly the following order:

    A "<" character.
    The element’s tag name.
    Optionally, one or more attributes, each of which must be preceded by one or more space characters.
    Optionally, one or more space characters.
    Optionally, a "/" character, which may be present only if the element is a void element.
    A ">" character.

so in HTML5, each one of <hr>, <hr >, <hr/> and <hr /> is correct.

(...also there's the "unless..." part following "A non-void element must have an end tag".)

Last edited by lolilolicon (2011-09-18 15:34:01)


This silver ladybug at line 28...

Offline

#6 2011-09-18 15:55:11

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

Re: [Solved] HTML5 - do I need to close void tags?

OK, thanks.

Offline

#7 2011-09-18 16:42:15

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] HTML5 - do I need to close void tags?

I forgot to post that http://w3schools.com/html5/tag_hr.asp is xhtml and not html5 so looking at the code of that page is irrelevant to the issue in question.
Should have checked this in the first place.


I now agree with lolilolicon that at least atm the '/' in <hr/> (and in other void elements) is optional. Furthermore, searching the current drafts, specs and recommendations I could only find <hr> in every example :-)
Adding '/' may have some benefits or it may be good practice, but it's not obligatory.


If your questions has been answered, please mark this thread as solved.

Offline

Board footer

Powered by FluxBB