HTML
<pre>
element
represents preformatted text which is to be presented exactly as written in the HTML file.
The text is typically rendered using a non-proportional ("
monospace
") font. Whitespace inside this element is displayed as written.
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.
| 内容类别 | 流内容 ,可触及内容。 |
|---|---|
| 准许内容 | 措词内容 . |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents | Any element that accepts flow content . |
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles | 任何 |
| DOM 接口 |
HTMLPreElement
|
此元素只包括 全局属性 .
cols
width
. To achieve such an effect, use CSS
width
代替。
width
width
代替。
wrap
white-space
代替。
<p>Using CSS to change the font color is easy.</p>
<pre>
body {
color: red;
}
</pre>
It is important to provide an alternate description for any images or diagrams created using preformatted text. The alternate description should clearly and concisely describe the image or diagram's content.
People experiencing low vision conditions and browsing with the aid of assistive technology such as a screen reader may not understand what the preformatted text characters are representing when they are read out in sequence.
A combination of the
<figure>
and
<figcaption>
elements, supplemented by a combination of an
id
和
ARIA
role
and
aria-labelledby
attributes allow the preformatted text to be announced as an image, with the
figcaption
serving as the image's alternate description.
<figure role="img" aria-labelledby="cow-caption">
<pre>
___________________________
< I'm an expert in my field. >
---------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
</pre>
<figcaption id="cow-caption">
A cow saying, "I'm an expert in my field." The cow is illustrated using preformatted text characters.
</figcaption>
</figure>
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of '<pre>' in that specification. |
实时标准 | No significant change from HTML5 |
|
HTML5
The definition of '<pre>' in that specification. |
推荐 | No significant change from HTML 4.01 Specification |
|
HTML 4.01 Specification
The definition of '<pre>' in that specification. |
推荐 |
Deprecated the
cols
属性
|
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
pre
|
Chrome 完整支持 Yes | 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 |
cols
弃用
非标
|
Chrome 不支持 No | Edge 不支持 No | Firefox 不支持 1 — 29 | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 不支持 4 — 29 | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
width
弃用
非标
|
Chrome
完整支持
Yes
注意事项
|
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
注意事项
|
wrap
弃用
非标
|
Chrome ? | Edge ? | Firefox 完整支持 1 | IE ? | Opera ? | Safari ? | WebView Android ? | Chrome Android ? | Firefox Android 完整支持 4 | Opera Android ? | Safari iOS ? | Samsung Internet Android ? |
完整支持
不支持
兼容性未知
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
见实现注意事项。
white-space
,
word-break
<code>