Self-closing tag syntax - who is right? (should I care?)

30 views
Skip to first unread message

Omar KN

unread,
Sep 29, 2022, 2:23:13 PM9/29/22
to BBEdit Talk
Hi and good day,

So now BREAK should be only <br> in HTML5.

Until a week ago the w3 corrector marked <br /> as the only correct way.

w3: 
"Self-closing tag syntax in text/html documents is widely discouraged." Some for 

BBEdit ( CTRL - CMD - Y) marks the <br /> as necessary.

(And then there are flavours of HTML ), I'm using <!doctype HTML>.

So a little confused, which way to take?

Byers Media

unread,
Sep 29, 2022, 3:45:23 PM9/29/22
to bbe...@googlegroups.com
I do not use the break tag very often, try to avoid it when I can, but when I have no other option, I just use <br />

Never had a problem. and since I am old school, seeing <br> just seems unfinished -- to me.

- gerald

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/6cfb6225-e06f-4ab9-ba6d-8b90a7c0ff00n%40googlegroups.com.

Byers Home Page

11773 Slow Poke Lane, Grass Valley, California 95945
Byers is committed to protecting your health and safety with a Virtual Consultation.

Reviews on Google • Give Us Feedback

We are here to help you Stay Safe!

Darren Duncan

unread,
Sep 30, 2022, 8:40:36 AM9/30/22
to bbe...@googlegroups.com
Modern HTML must follow all the XML rules, which is that tags in pairs look like
"<foo></foo>" and standalone tags look like "<foo/>". Whether or not there is
whitespace before a "/" is a stylistic choice, but the "/" MUST be present in
standalone tags. Having "<br>" by itself is wrong, full stop. -- Darren Duncan

On 2022-09-29 11:23 a.m., Omar KN wrote:
> Hi and good day,
>
> So now BREAK should be only <br> in HTML5.
>
> Until a week ago the w3 corrector marked <br /> as the only correct way.
>
> w3:
> "Self-closing tag syntax in text/html documents is widely discouraged." Some for
>
> BBEdit ( CTRL - CMD - Y) marks the <br /> as necessary.
>
> (And then there are flavours of HTML ), I'm using <!doctype HTML>.
>
> So a little confused, which way to take?
>
> /
>
> with best regards, Omar KN, Stockholm, Sweden
>
>
> Related:
>
> link1
>
> html - Are (non-void) self-closing tags valid in HTML5? - Stack Overflow
> <https://stackoverflow.com/questions/3558119/are-non-void-self-closing-tags-valid-in-html5>
>
> link2
>
> HTML 5: Is it <br>, <br/>, or <br />? - Stack Overflow
> <https://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br>

Neil Faiman

unread,
Sep 30, 2022, 12:14:46 PM9/30/22
to BBEdit Talk Mailing List
On Sep 29, 2022, at 2:23 PM, Omar KN <omn...@gmail.com> wrote:

So now BREAK should be only <br> in HTML5.

Until a week ago the w3 corrector marked <br /> as the only correct way.

w3: 
"Self-closing tag syntax in text/html documents is widely discouraged." Some for 

If you’re using <!doctype HTML>, you’re writing HTML5.

According to the HTML5 specs at https://html.spec.whatwg.org/, (dated September 28, 2022) Section 13.1.2.1, Start tags:

• After the attributes, or after the tag name if there are no attributes, there may be one or more ASCII whitespace. (Some attributes are required to be followed by a space. See the attributes section below.)
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.
• Finally, start tags must be closed by a U+003E GREATER-THAN SIGN character (>).

The enumeration of void elements in section 13.1.2 lists br as a void element.

Therefore, at least in the eyes of WHATWG, the slash is optional in a <br> tag.

Regards,
Neil Faiman

Neil Faiman

unread,
Sep 30, 2022, 12:23:28 PM9/30/22
to BBEdit Talk Mailing List
On Sep 30, 2022, at 12:38 AM, Darren Duncan <dar...@darrenduncan.net> wrote:

Modern HTML must follow all the XML rules, which is that tags in pairs look like "<foo></foo>" and standalone tags look like "<foo/>".  Whether or not there is whitespace before a "/" is a stylistic choice, but the "/" MUST be present in standalone tags.  Having "<br>" by itself is wrong, full stop. -- Darren Duncan

According to the HTML5 standard at WHATWG, https://html.spec.whatwg.org/, dated 28 September 2022, in Section 1.8, HTML vs XML syntax (non-normative):

There are various concrete syntaxes that can be used to transmit resources that use this abstract language, two of which are defined in this specification.

The first such concrete syntax is the HTML syntax. This is the format suggested for most authors. It is compatible with most legacy web browsers. If a document is transmitted with the text/html MIME type, then it will be processed as an HTML document by web browsers. This specification defines the latest HTML syntax, known simply as "HTML".

The second concrete syntax is XML. When a document is transmitted with an XML MIME type, such as application/xhtml+xml, then it is treated as an XML document by web browsers, to be parsed by an XML processor. Authors are reminded that the processing for XML and HTML differs; in particular, even minor syntax errors will prevent a document labeled as XML from being rendered fully, whereas they would be ignored in the HTML syntax.


See also my previous reply to Omar KN, quoting from the same standard to the effect that the terminal slash in void element tags is optional.

I believe that the only HTML version that required consistency with XML syntax was XHTML, which is scarcely a modern HTML at this point.

Regards,
Neil Faiman
Reply all
Reply to author
Forward
0 new messages