pre

<pre>

HTML <pre>元素表示预定义格式文本。在该元素中的文本通常按照原文件中的编排,以等宽字体的形式展现出来,文本中的空白符(比如空格和换行符)都会显示出来。(紧跟在 <pre> 开始标签后的换行符也会被省略)

内容类别 Flow content, palpable content.
允许的内容 Phrasing content.
标记遗漏没有,起始和结束标签都是强制性的。
允许父母任何接受 flow content 的元素。
允许ARIA角色任何
DOM界面HTMLPreElement

属性

这个元素只包含全局属性。

cols定义每行的最大字符数。这是一个非标准的属性,作用与width相同。要实现这样的效果,应该使用CSS。

例子

<!-- Some example CSS code --> <pre> body { color:red; } </pre>

结果

body { color:red; }

规范

SpecificationStatusComment
HTML Living StandardThe definition of '<pre>' in that specification.Living StandardNo significant change from HTML Living Standard
HTML5The definition of '<pre>' in that specification.RecommendationNo significant change from HTML 4.01 Specification
HTML 4.01 SpecificationThe definition of '<dl>' in that specification.RecommendationDeprecated the cols attribute

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support(Yes)(Yes)1(Yes)(Yes)(Yes)
colsNoNo1 — 29NoNoNo
width(Yes)1(Yes)112(Yes)1(Yes)1(Yes)1
wrap?No1???

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(Yes)(Yes)(Yes)1(Yes)(Yes)(Yes)
colsNoNoNo1 — 29NoNoNo
width(Yes)1(Yes)1(Yes)112(Yes)1(Yes)1(Yes)1
wrap??No1???