HTML: What's the correct form of BR?

2020-04-01 08:34发布

How is correct to write the br tag in html?

<br />

or

<br>

or anything else? :))

8条回答
【Aperson】
2楼-- · 2020-04-01 08:53

@CIRK: HTML4, <br>. XHTML 1.x, <br />. <br/> is also acceptable.

查看更多
forever°为你锁心
3楼-- · 2020-04-01 08:54

it is most formal to use <br/> this is then XHTML compliant - all opening tags have corresponding end tag.

查看更多
淡お忘
4楼-- · 2020-04-01 08:55

It does not need an end tag, so

<br>

is correct for HTML, and

<br />

for XHTML.

查看更多
倾城 Initia
5楼-- · 2020-04-01 08:56
<br/>.  

Here:

Some of the most common errors in the usage of XHTML are:
Not closing empty elements (elements without closing tags in HTML4)
Incorrect: <br>
Correct: <br />
Note that any of these is acceptable in XHTML: <br></br>, <br/>, and <br />. Older HTML-only browsers interpreting it as HTML will generally accept <br> and <br />.
查看更多
虎瘦雄心在
6楼-- · 2020-04-01 08:57

In HTML4.01 or earlier, it is <br>. This is case-insensitive, and whitespace between the r and the > is ignored.

In all forms of XHTML it is <br/>. This is case-sensitive, and again whitespace between the r and the /> is ignored. <br></br> is also allowed, but unusual (there are backwards-compatibility issues, it's extra typing, and allows for bugs if you introduce more content between the tags by mistake, but it does sometimes happen in XML-programattically produced code).

Since some earlier browsers that would parse XHTML as earlier HTML would choke on <br/> but not on <br /> such extra whitespace is the norm, for backwards compatibility (more backwards kludging it, but still...).

In HTML5 either are allowed (but not <br></br>).

查看更多
淡お忘
7楼-- · 2020-04-01 09:04

In HTML (up to version 4) it's <br>And in XHTML it's <br /> because the tag has to be properly closed with an /

HTML5 <br> is the best option.

查看更多
登录 后发表回答