elements go <br>

permalink
report
reply
44 points
*

If it’s stupid, and it works…

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
permalink
report
reply
2 points
*

Fairly straightforward breakdancing.


Or just break stepping.




permalink
report
parent
reply
7 points

This made my eye twitch

permalink
report
reply
70 points

I’m sorry Timmy but you’re not allowed to have any dessert unless you close your tags like I taught you. Your grandmother was XMLish and you need to carry on our family tradition.

I thought you might do something like this so I got you a backup one from AO3.

permalink
report
reply
33 points

🤓 ackshually that’s not the HTML spec. Void elements should not have trailing slashes.

https://developer.mozilla.org/en-US/docs/Glossary/Void_element

permalink
report
parent
reply
6 points

TIL. Funny thing, though, is that they give an example of how to use <br> and have it with trailing slashes. And then explain that trailing or preceding slash will be ignored, anyway ¯\_(ツ)_/¯

permalink
report
parent
reply
18 points

> Clicks on <br>
> Example is <br />


The actual thing that matters is that the / is ignored so (unlike with XML I believe) you can’t self-close a non-void element by adding a trailing /. But “void elements should not have trailing slashes” is extrapolation on your part; the trailing slash improves readability and is kosher since it doesn’t act as a self-close.

permalink
report
parent
reply
7 points

An explanation of this problem can be found on the official W3C HTML validator wiki.

HTML parsers only allow this to stop pages breaking when developers make mistakes; see this Computerphile video. ‘Able to be parsed correctly’ is not the soul criterion for it a syntax being preferred, otherwise we would all leave our <p> elements unclosed.

Yes, it is not “incorrect” to write <br/>, but it is widely considered bad practice. For one, it makes it inconsistent with XML. Linters will often even “correct” this for you.

I personally find the official style (<br>) to be more readable, but this is a matter of personal opinion. Oh, and I used to have the same stance as you, but I also used to think that Python’s whitespace-based syntax was superior…

At the end of the day, regardless of anyone’s opinion, we should come to SOME consensus…and considering that W3C already endorses <br>, we should use this style.

permalink
report
parent
reply
12 points
*

It’s not extrapolation on my part, the HTML spec is pretty direct about it:

  1. 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 (/), which on foreign elements marks the start tag as self-closing. On void elements, it does not mark the start tag as self-closing but instead is unnecessary and has no effect of any kind. For such void elements, it should be used only with caution — especially since, if directly preceded by an unquoted attribute value, it becomes part of the attribute value rather than being discarded by the parser.

https://html.spec.whatwg.org/multipage/syntax.html#start-tags

I don’t think it’s an extrapolation to say that code which is “unnecessary and has no effect of any kind” should be omitted.

And yeah, I linked the MDN docs because they’re easier to read but if they disagree then obviously the spec is the correct one.

permalink
report
parent
reply
1 point

Trailing slash lets you do this though:

For example, in the case of <div/>Some text, browsers interpret this as <div>Some text</div>, treating the slash as ignored and considering the div element to encapsulate the text that follows.

permalink
report
parent
reply
2 points

Wasn’t the space before the closing / only because IE was dumb?

permalink
report
parent
reply
1 point

It’s XHTML, isn’t it?

permalink
report
parent
reply
6 points

found the react dev

permalink
report
parent
reply
4 points

Take that back!

(I’m actually a DB specialist but I have done a lot of full stack work in different portions of my career)

permalink
report
parent
reply
1 point

It’s actually more confusing/less correct to close bodyless elements in HTML. Since HTML treats “/>” the same way as “>” which could lead to a “/>” tag not actually being closed, if it is used on a non-selfclosing tag.

permalink
report
parent
reply
11 points

( ( laughs in old… ) )

permalink
report
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.5K

    Monthly active users

  • 809

    Posts

  • 12K

    Comments