Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It’s because the trailing “/“ has zero semantics now, by definition. You can add or remove it from any tag, and it doesn’t change the meaning of your HTML.

    <div/>
    some text
is thus equivalent to

    <div>
    some text
which in the absence of any further tags or content is interpreted as

    <div>
    some text
    </div>
(Note however the exception for foreign content like SVG, as noted in the article.)


What's your actual rule here? How would you handle:

    <div/>
    some text
    and some more text
or

    <div/>
    some text, an <img src="" />, and some more text
or

    <div/>
    some <em>emphasized</em> text
??


All 3 cases are treated the same:

https://imgur.com/a/dpLoXvo


Read the HTML5 spec. The point here is that `<div/>` behaves exactly the same as `<div>` would.


It is HTML5. https://html.spec.whatwg.org/multipage/syntax.html#optional-..., if I'm not mistaken. Rules are of the form:

    A td element's end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
Edit: I don't know the "div" rules. Don't see that here.

Edit2: I'm actually curious on if what I put here is wrong.


You’re quoting a description of implicit end tags, but the conversation is about self‐closing tags, which are a different thing.


Sorta? The thread was about how odd it is that <div> has implicit end tags?

So, makes sense that the topic seems different, but it is the explanation for why a div grows to contain everything under it. For example, this is needed to know why the div in the following text closes.

    <table>
      <tr>
        <td>Some cell
        <td>Another cell
      <tr>
        <td>And <div>Another
      <tr>
        <td>With more stuff. 
Right? I get that the original confusion is thinking you can make a self closing div. But the fact that it expands to cover things that come after it requires you to know about the implicit closing. Hard to understand one without understanding the other.

Edit: I suppose it would be better for me to say that none of the examples on the immediate parent post are different, because none of them close the div? It isn't that the one div expands to cover everything after it, is that nothing caused it to be closed. Indeed, if those are just snippets from a document, you can't be sure that stuff that comes after it is also not included in the div.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: