• xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    49
    ·
    1 year ago

    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.

      • azertyfun@sh.itjust.works
        link
        fedilink
        arrow-up
        18
        arrow-down
        1
        ·
        1 year ago

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

        • traches@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          11
          ·
          1 year ago

          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.

          • azertyfun@sh.itjust.works
            link
            fedilink
            arrow-up
            6
            ·
            1 year ago

            To be annoyingly nitpicky, how is “unnecessary” defined in this context? Whitespace is usually “unnecessary” but I quite like it for readability.

            I broadly agree with you though, the W3C spec changes things.

        • dukk@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          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.

          • KairuByte@lemmy.dbzer0.com
            link
            fedilink
            arrow-up
            5
            ·
            1 year ago

            This is terrible.

            You should never rely on a browser interpreting a non standard use in a specific way. It can change at any moment, and wouldn’t be reliably reversed because it’s inherently non standard.

      • lad@programming.dev
        link
        fedilink
        English
        arrow-up
        6
        ·
        1 year ago

        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 ¯\_(ツ)_/¯

    • calcopiritus@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      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.