HTML 5: Is it
,
, or
?

后端 未结 29 3255
滥情空心
滥情空心 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:48

    Both <br> and <br /> are acceptable in HTML5, but in the spirit of HTML, <br> should be used. HTML5 allows closing slashes in order to be more compatible with documents that were previously HTML 4.01 and XHTML 1.0, allowing easier migration to HTML5. Of course, <br/> is also acceptable, but to be compatible with some older browsers, there should be a space before the closing slash (/).

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

    Most of the cases in HTML, the tags are in pair. But for a line break you don't need a pair of tags. Therefore to indicate this, HTML uses <br/> format. <br/> is the right one. Use that format.

    <br> tag has no end tag in HTML In XHTML, the <br> tag must be properly closed, like this: <br />

    In XML every tag must be closed. XHTML is an extension of XML, hence all the rules of XML must be followed for valid XHTML. Hence even empty tags (nodes without child nodes) like
    should be closed. XML has a short form called self closing tags for empty nodes. You can write <br></br> as <br />. Hence in XHTML <br /> is used.

    HTML is very lenient in this regard, and there is no such rule. So in HTML empty nodes like <br> <hr> <meta> etc are written without the closing forward slash.

    HTML

    <br>
    <hr>
    <meta name="keywords" content="">
    <link rel="canonical" href="http://www.google.com/">
    

    XHTML

    <br />
    <hr />
    <meta name="keywords" content="" />
    <link rel="canonical" href="http://www.google.com/" />
    

    Not all tags can be self closed. For example, a tag like <script src="jQuery.min.js" /> is not allowed by XHTML DTD.

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

    If you're interested in comparability (not compatibility, but comparability) then I'd stick with <br />.

    Otherwise, <br> is fine.

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

    <br/> is the most appropriate one. This tag notation can also be used in Reactjs where a line break is required instead of <br>

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

    In HTML (up to HTML 4): use <br>

    In HTML 5: <br> is preferred, but <br/> and <br /> is also acceptable

    In XHTML: <br /> is preferred. Can also use <br/> or <br></br>

    Notes:

    • <br></br> is not valid in HTML 5, it will be thought of as two line breaks.
    • XHTML is case sensitive, HTML is not case sensitive.
    • For backward compatibility, some old browsers would parse XHTML as HTML and fail on <br/> but not <br />

    Reference:

    • http://www.w3schools.com/tags/tag_br.asp
    • http://en.wikipedia.org/wiki/XHTML
    0 讨论(0)
提交回复
热议问题