HTML 5: Is it
,
, or
?

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

    IMHO it is better to use the regular notation (<br />) instead of the forgiving notation (<br>) for the following reasons:

    Consistency

    In your HTML there is probably some SVG and SVG only support the regular notation (e.g. <rect />).

    Hackability

    It is not a case that frameworks like React and NativeScript use an XML notation.
    Your markup code will be easier to parse.

    Clarity

    The regular notation is easier to read and understand, even late at night.

    Specifications

    Both <br> and <br /> are valid HTML tags.

    Conclusion

    If you use a full-fledged text editor configure it to use the regular notation (which is called XHTML by Emmet).
    For instance, in Visual Studio Code you just have to add the following line to your settings:

    "emmet.syntaxProfiles": {"html": "xhtml"}
    
    0 讨论(0)
  • 2020-11-22 00:39

    The elements without having end tags are called as empty tags. In html 4 and html 5, end tags are not required and can be omitted.

    In xhtml, tags are so strict. That means must start with start tag and end with end tag.

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

    <br> is sufficient but in XHTML <br /> is preferred according to the WHATWG and according to the W3C.

    To quote Section 8.1.2.1 of HTML 5.2 W3C Recommendation, 14 December 2017

    Start tags must have the following format:

    1. After the attributes, or after the tag name if there are no attributes, there may be one or more space characters. (Some attributes are required to be followed by a space. See §8.1.2.3 Attributes below.)

    2. 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 (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

    If you use Dreamweaver CS6, then it will autocomplete as <br />.

    To validate your HTML file on W3C see : http://validator.w3.org/

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

    <br> works just fine. The stricter versions like XHTML require you to add the closing, and really old versions of HTML that do not include a DOCTYPE make <br> a non-void tag, like <br></br>.

    Sum up: <br> is fine. Other ones are also just fine.

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


    works just fine in HTML5. HTML5 allows a little more leeway than XHTML

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

    Just use <br>. Do not use <br></br>. <br> is a special tag which doesn't need a closing unlike most tags.

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