HTML:BR 的正确形式是什么?

发布于 2024-10-04 10:33:01 字数 156 浏览 4 评论 0原文

html中的br标签怎么写才是正确的?

<br />

<br>

其他什么? :))

How is correct to write the br tag in html?

<br />

or

<br>

or anything else? :))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

策马西风 2024-10-11 10:33:01

这取决于您使用的文档类型。在 HTML 的原始版本(直到 HTML4)中,只有
是正确的。在 XHTML(基于 XML)中,只有
是正确的。在 HTML5 中,尽管
是首选,但两者都是允许的。

It depends on the doctype you're using. In the original versions of HTML (up to HTML4), only <br> is correct. In XHTML (which is based on XML), only <br /> is correct. In HTML5, both are allowed although <br> is preferred.

自由如风 2024-10-11 10:33:01

不需要结束标记,因此

<br>

对于 HTML 和

<br />

XHTML 来说都是正确的。

It does not need an end tag, so

<br>

is correct for HTML, and

<br />

for XHTML.

不即不离 2024-10-11 10:33:01

在 HTML4.01 或更早版本中,它是
。这是不区分大小写的,并且 r> 之间的空格将被忽略。

在所有形式的 XHTML 中,它都是
。这是区分大小写的,并且 r/> 之间的空格再次被忽略。

也是允许的,但不常见(存在向后兼容性问题,这是额外的输入,并且如果您错误地在标签之间引入更多内容,则可能会出现错误,但是它有时确实会发生在以 XML 编程方式生成的代码中)。

由于一些将 XHTML 解析为早期 HTML 的早期浏览器会在
上阻塞,但在
gt;
上不会阻塞,因此额外的空格是常态,为了向后兼容(更多向后拼凑它,但仍然......)。

在 HTML5 中,两者都是允许的(但不允许

)。

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>).

千纸鹤 2024-10-11 10:33:01

@CIRK:HTML4,
。 XHTML 1.x,

也是可以接受的。

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

夏末的微笑 2024-10-11 10:33:01

您应该使用
因为它尊重 XHTML、HTML 和一般标准 (XML)。因为每个xml标签都需要关闭。

You should use <br /> because it respect the standards XHTML, HTML and in general (XML). Because every xml tag needs to close.

凉城已无爱 2024-10-11 10:33:01

在 HTML(最高版本 4)中,它是
在 XHTML 中,它是
因为标签必须用 /

HTML5 < 正确关闭code>
是最好的选择。

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.

笑梦风尘 2024-10-11 10:33:01

最正式的是使用

这就是 XHTML 兼容的 - 所有开始标签都有相应的结束标签。

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

不再见 2024-10-11 10:33:01
<br/>.  

此处:

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 />.
<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 />.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文