HTML 5: Is it
,
, or
?

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

    Well all I know is that <br /> gives a break with a white line and <br> just gives a break in some cases. This happened to me when I was setting up an IPN-script (PHP) and sent mails and checked the inbox for it. Dont know why but I only got the message to look neat using both <br /> and <br>

    Have a look at the mail here: http://snag.gy/cLxUa.jpg

    The first two sections of text is seperated by <br />, hence the whitespace lines, the last three rows of text in the bottom and the last section is seperated by <br> and just gives new row.

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

    According to the spec the expected form is <br> for HTML 5 but a closing slash is permitted.

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

    I would recommend using <br /> for the following reasons:

    1) Text and XML editors that highlight XML syntax in different colours will highlight properly with <br /> but this is not always the case if you use <br>

    2) <br /> is backwards-compatible with XHTML and well-formed HTML (ie: XHTML) is often easier to validate for errors and debug

    3) Some old parsers and some coding specs require the space before the closing slash (ie: <br /> instead of <br/>) such as the WordPress Plugin Coding spec: http://make.wordpress.org/core/handbook/coding-standards/html/

    I my experience, I have never come across a case where using <br /> is problematic, however, there are many cases where <br/> or especially <br> might be problematic in older browsers and tools.

    0 讨论(0)
  • 2020-11-22 00:29
    1. If you are outputting HTML on a regular website you can use <br> or <br/>, both are valid anytime you are serving HTML5 as text/html.

    2. If you are serving HTML5 as XHTML (i.e. content type application/xhtml+xml, with an XML declaration) then you must use a self closing tag like so: <br/>.

      If you don't the some browsers may flat out refuse to render your page (Firefox in particular is very strict about rendering only valid xhtml+xml pages).

      As noted in 1. <br/> is also valid for HTML5 that happens to be generated as XML but served as a regular text/html without an XML declaration (such as from an XSL Transform that generates web pages, or something similar).

    To clear up confusion: Putting a space before the slash isn't required in HTML5 and doesn't make any difference to how the page is rendered (if anyone can cite an example I'll retract this, but I don't believe it's true - but IE certainly does a lot of other odd things with all forms of <br> tags).

    The excellent validator at http://validator.w3.org is really helpful for checking what's valid (although I'm not sure you can rely on it to also check content-type).

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

    In HTML <br> and in XHTML <br/>.

    I will suggest you to use <br/>.

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

    XML requires all tags to have a corresponding closing tag. So there is a special short-hand syntax for tags without inner contents.

    HTML5 is not XML, so it should not pose such a requirement. Neither is HTML 4.01.

    For instance, in HTML5 specs, all examples with br tag use <br> syntax, not <br/>.

    UPD Actually, <br/> is permitted in HTML5. 9.1.2.1, 7.

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