<br>:换行元素

<br> HTML 元素在文本中产生换行符(回车符)。它对于写诗或地址很有用,因为行的划分很重要。

¥The <br> HTML element produces a line break in text (carriage-return). It is useful for writing a poem or an address, where the division of lines is significant.

Try it

从上面的示例中可以看出,我们希望文本中断的每个点都包含一个 <br> 元素。<br> 之后的文本再次从文本块下一行的开头开始。

¥As you can see from the above example, a <br> element is included at each point where we want the text to break. The text after the <br> begins again at the start of the next line of the text block.

注意:不要使用 <br> 在段落之间创建页边距;将它们封装在 <p> 元素中并使用 CSS margin 属性来控制它们的大小。

¥Note: Do not use <br> to create margins between paragraphs; wrap them in <p> elements and use the CSS margin property to control their size.

属性

¥Attributes

该元素的属性包括 全局属性

¥This element's attributes include the global attributes.

已弃用的属性

¥Deprecated attributes

clear Deprecated

指示中断后下一行的开始位置。

使用 CSS 设计样式

¥Styling with CSS

<br> 元素有一个明确定义的用途 - 在文本块中创建换行符。因此,它没有自己的尺寸或视觉输出,并且你几乎无法对其进行样式设置。

¥The <br> element has a single, well-defined purpose — to create a line break in a block of text. As such, it has no dimensions or visual output of its own, and there is very little you can do to style it.

你可以在 <br> 元素本身上设置 margin,以增加块中文本行之间的间距,但这是一个不好的做法 - 你应该使用为此目的而设计的 line-height 属性。

¥You can set a margin on <br> elements themselves to increase the spacing between the lines of text in the block, but this is a bad practice — you should use the line-height property that was designed for that purpose.

示例

¥Examples

简单的 br

¥Simple br

在以下示例中,我们使用 <br> 元素在邮政地址的不同行之间创建换行符:

¥In the following example we use <br> elements to create line breaks between the different lines of a postal address:

html
Mozilla<br />
331 E. Evelyn Avenue<br />
Mountain View, CA<br />
94041<br />
USA<br />

结果

¥Result

无障碍问题

¥Accessibility concerns

使用 <br> 创建单独的文本段落不仅是不好的做法,而且对于借助屏幕阅读技术进行导航的人来说也是有问题的。屏幕阅读器可能会宣布该元素的存在,但不会宣布 <br> 中包含的任何内容。对于使用屏幕阅读器的人来说,这可能是一种令人困惑和令人沮丧的体验。

¥Creating separate paragraphs of text using <br> is not only bad practice, it is problematic for people who navigate with the aid of screen reading technology. Screen readers may announce the presence of the element, but not any content contained within <br>s. This can be a confusing and frustrating experience for the person using the screen reader.

使用 <p> 元素,并使用 margin 等 CSS 属性来控制它们的间距。

¥Use <p> elements, and use CSS properties like margin to control their spacing.

技术总结

¥Technical summary

内容类别 流量内容, 措辞内容.
允许的内容 没有任何;这是 void element
标签遗漏 必须有开始标记,并且不能有结束标记。在 XHTML 文档中,将此元素写为 <br />
允许的父级 任何接受 措辞内容 的元素。
隐式 ARIA 角色 没有对应的角色
允许的 ARIA 角色 none, presentation
DOM 接口 HTMLBRElement

规范

Specification
HTML Standard
# the-br-element

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also