Space Before Closing Slash?

后端 未结 8 1744
说谎
说谎 2020-11-27 15:29

I\'ve frequently seen a space preceding the closing slash in XML and HTML tags. The XHTML line break is probably the canonical example:


<
相关标签:
8条回答
  • 2020-11-27 16:02

    The space just makes the tags more readable. I am a big proponent of formatting for more readable code. Little things like that go a long way. Without the space the closing tag blends in with the opening tag. It takes just an instant longer for me to process it as I am quickly reading the code.

    0 讨论(0)
  • 2020-11-27 16:10

    I think that the white space is a way to reinforce the idea that this tag is empty and it closes itself.

    Today i don't use the white space anymore because i never had a problem with no white space.

    0 讨论(0)
  • 2020-11-27 16:12

    The answer is people wish to adhere to Appendix C of the XHTML1.0 specification. Which you only need to do if you are serving XHTML as text/html. Which most people do, because XHTML's real MIME type (application/html+xml) does not work in Internet Explorer.

    No current browser cares for the space. Browsers are very tolerant of these things.

    The space used to be required to ensure HTML parsers treated the trailing slash as an unrecognised attribute.

    0 讨论(0)
  • 2020-11-27 16:14

    Are those issues still relevant or are we still adding extra spaces for the sake of, say, IE3 compatibility?

    You were close - it is for Netscape 4.

    It is interesting to see other rationalisations, but that's all it was meant for.

    0 讨论(0)
  • 2020-11-27 16:14

    In XHTML, br tags must be closed, but the space is not necessary. It's a stylistic thing. In HTML, br tags cannot be closed, so both are wrong.

    0 讨论(0)
  • 2020-11-27 16:16

    What if there was a very lazy html writer out there or maybe he had a fear of quotation marks. Consider the following if you were his robot page crawler...

    <img src=http://myunquotedurl.com/image.jpg />

    versus

    <img src=http://myunquotedurl.com/image.jpg/>

    This might seem small but look what it can do if the space isn't there. The robot won't know if the slash is part of the url or part of the closing tag.

    0 讨论(0)
提交回复
热议问题