this post was submitted on 20 Jul 2024
581 points (98.2% liked)

Programmer Humor

19564 readers
1077 users here now

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

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 33 points 3 months ago (15 children)

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

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

[–] [email protected] 18 points 3 months ago (12 children)

> 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.

[–] [email protected] 1 points 3 months ago (2 children)

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.

[–] [email protected] 3 points 3 months ago

Why would you want that.

load more comments (1 replies)
load more comments (10 replies)
load more comments (12 replies)