HTML 5: Is it
,
, or
?

后端 未结 29 3236
滥情空心
滥情空心 2020-11-22 00:26

I\'ve tried checking other answers, but I\'m still confused — especially after seeing W3schools HTML 5 reference.

I thought HTML 4.01 was supposed to \"allow\" singl

相关标签:
29条回答
  • 2020-11-22 00:45

    Both <br> and <br/> will do fine but I prefer <br/> because it's slightly more logical. It is logical to expect a closing tag whenever there is an opening tag. Therefore your code is slightly easier to read if you don't use an opening tag when there isn't going to be a closing tag.

    All browser (except possibly some very old ones that don't matter) will display both exactly the same. However, <br> is not xHTML complient.

    0 讨论(0)
  • 2020-11-22 00:45

    <br> and <br/> render differently. Some browsers interpret <br/> as <br></br> and insert two line breaks

    0 讨论(0)
  • 2020-11-22 00:46

    Simply <br> is sufficient.

    The other forms are there for compatibility with XHTML; to make it possible to write the same code as XHTML, and have it also work as HTML. Some systems that generate HTML may be based on XML generators, and thus do not have the ability to output just a bare <br> tag; if you're using such a system, it's fine to use <br/>, it's just not necessary if you don't need to do it.

    Very few people actually use XHTML, however. You need to serve your content as application/xhtml+xml for it to be interpreted as XHTML, and that will not work in old versions of IE - it will also mean that any small error you make will prevent your page from being displayed in browsers that do support XHTML. So, most of what looks like XHTML on the web is actually being served, and interpreted, as HTML. See Serving XHTML as text/html Considered Harmful for some more information.

    0 讨论(0)
  • 2020-11-22 00:46

    If you are using HTML5, then using <br> is the right way to go :)

    0 讨论(0)
  • 2020-11-22 00:46

    <br> doesn't need an end tag. As per W3S:

    The <br> tag is an empty tag which means that it has no end tag.

    It's also supported by all major browsers.

    For more information, visit here.

    0 讨论(0)
  • 2020-11-22 00:47

    Ummm.....does anyone know a SINGLE vendor, user-agent, or browser maker that has ever followed the W3C Specifications 100%??? So if HTML5 says it supports all three break element versions, you can bet the vendors support the same and even more sloppier versions!

    The ONLY thing that matters in this debate is to CONSISTENTLY use coding that also happens to follow XML specifications as well as HTML specifications when possible. That means you should use the correct XML version of the break tag and encourage all your team to do the same:

    <br />
    

    The same space-slash format should apply for the img, a, hr, and meta tags in your code. Why? Because:

    1. Its is backwards compatible with older XHTML user-agents / browsers
    2. The browser vendors support the XML version anyway so the HTML5 specification is moot.
    3. The sloppy implementations of most user-agents today, in the past, and in the future will accept it.
    4. It allows your markup to be comparable with XML standards should you need to go back to creating XHTML/XML documents from your markup.
    5. It's "good coding practice" for ALL WEB DEVELOPERS to keep using solid markup practices that follow XML, including coding in all lower case, quoted attributes, escaped XML characters, etc. etc. Why? In the future if you have to switch to XML data you automatically code and think in XML.
    6. We can only hope that in the future World Wide Web, we move away from private vendor-implemented standards and go back to solid, reliable, verified markup that parses faster, moves data over the wires faster, and make our future Internet a more standardized medium using XML.

    Besides, in the robotic and machine world that's here, where robots don't have the same Human-interface coding problems HTML5 solves for us, they will gladly go back to XML data systems and parse such UI web pages much faster when converted to XML data.

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