HTML
<br>
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.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
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.
注意
: Do not use
<br>
to create margins between paragraphs; wrap them in
<p>
elements and use the
CSS
margin
property to control their size.
This element's attributes include the 全局属性 .
clear
Indicates where to begin the next line after the break.
<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.
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.
In the following example we use
<br>
elements to create line breaks between the different lines of a postal address:
Mozilla<br> 331 E. Evelyn Avenue<br> Mountain View, CA<br> 94041<br> USA<br>
The result looks like so:
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>
elements, and use CSS properties like
margin
to control their spacing.
| 内容类别 | 流内容 , 措词内容 . |
|---|---|
| 准许内容 | None, it is an empty element . |
| Tag omission |
Must have a start tag, and must not have an end tag. In XHTML documents, write this element as
<br />
.
|
| Permitted parents | Any element that accepts 措词内容 . |
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles |
none
,
presentation
|
| DOM 接口 |
HTMLBRElement
|
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
br
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
clear
弃用
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
弃用。不要用于新网站。