Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 998115 of <pre>

  • Revision slug: Web/HTML/Element/pre
  • Revision title: <pre>
  • Revision id: 998115
  • Created:
  • Creator: Tigt
  • Is current revision? No
  • Comment

Revision Content

{{HTMLRef}}

The HTML <pre> element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional ("monospace") font exactly as it is laid out in the file. Whitespace inside this element is displayed as typed.

Note: you will need to escape any contained '<' characters as '&lt;' to make sure enclosed code is not interpreted as markup.

Content categories Flow content, palpable content.
Permitted content Phrasing content.
Tag omission {{no_tag_omission}}
Permitted parent elements Any element that accepts flow content.
DOM interface {{domxref("HTMLPreElement")}}

Attributes

This element only includes the global attributes.

{{htmlattrdef("cols")}} {{non-standard_inline}}{{obsolete_inline}}
Contains the preferred count of characters that a line should have. It was a non-standard synonym of {{htmlattrxref("width", "pre")}}. To achieve such an effect, use CSS {{Cssxref("width")}} instead.
{{htmlattrdef("width")}} {{obsolete_inline}}
Contains the preferred count of characters that a line should have. Though technically still implemented, this attribute has no visual effect; to achieve such an effect, use CSS {{Cssxref("width")}} instead.
{{htmlattrdef("wrap")}} {{non-standard_inline}}
Is a hint indicating how the overflow must happen. In modern browser this hint is ignored and no visual effect results in its present; to achieve such an effect, use CSS {{Cssxref("white-space")}} instead.

Examples

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

Result

body {
  color:red;
}

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'grouping-content.html#the-pre-element', '<pre>')}} {{Spec2('HTML WHATWG')}} No significant change from {{SpecName("HTML WHATWG")}}
{{SpecName('HTML5 W3C', 'grouping-content.html#the-pre-element', '<pre>')}} {{Spec2('HTML5 W3C')}} No significant change from {{SpecName("HTML4.01")}}
{{SpecName('HTML4.01', 'struct/text.html#h-9.3.4', '<dl>')}} {{Spec2('HTML4.01')}} Deprecated the cols attribute

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{CompatGeckoDesktop("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
width {{CompatVersionUnknown}}[1] {{CompatGeckoDesktop("1.0")}}
{{CompatGeckoDesktop("29.0")}}[1]
{{CompatVersionUnknown}}[1] {{CompatVersionUnknown}}[1] {{CompatVersionUnknown}}[1]
cols {{CompatNo}} {{CompatGeckoDesktop("1.0")}}
{{CompatNo}} {{CompatGeckoDesktop("29.0")}}
{{CompatNo}} {{CompatNo}} {{CompatNo}}
wrap {{CompatUnknown}} {{CompatGeckoDesktop("1.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
width {{CompatUnknown}} {{CompatGeckoMobile("1.0")}}{{CompatGeckoMobile("29.0")}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
cols {{CompatNo}} {{CompatGeckoMobile("1.0")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
wrap {{CompatUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Specifying the width attribute has no layout effect.

See also

  • CSS: {{Cssxref('white-space')}}, {{Cssxref('word-break')}}

Revision Source

<div>{{HTMLRef}}</div>

<p>The <strong>HTML <code>&lt;pre&gt;</code> element</strong> (or <em>HTML Preformatted Text</em>) represents preformatted text. Text within this element is typically displayed in a non-proportional ("<a href="/en-US/docs/XUL/Style/monospace">monospace</a>") font exactly as it is laid out in the file. Whitespace inside this element is displayed as typed.</p>

<div class="note">
<p><strong>Note:</strong> you will need to escape any contained '<code>&lt;</code>' characters as '<code>&amp;lt;</code>' to make sure enclosed code is not interpreted as markup.</p>
</div>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/Web/Guide/HTML/Content_categories">Content categories</a></th>
   <td><a href="/en-US/docs/Web/Guide/HTML/Content_categories#Flow_content">Flow content</a>, palpable content.</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td><a href="/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content">Phrasing content</a>.</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>{{no_tag_omission}}</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>Any element that accepts <a href="/en-US/docs/Web/Guide/HTML/Content_categories#Flow_content">flow content</a>.</td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLPreElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element only includes the <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("cols")}} {{non-standard_inline}}{{obsolete_inline}}</dt>
 <dd>Contains the <em>preferred</em> count of characters that a line should have. It was a non-standard synonym of {{htmlattrxref("width", "pre")}}. To achieve such an effect, use CSS {{Cssxref("width")}} instead.</dd>
 <dt>{{htmlattrdef("width")}} {{obsolete_inline}}</dt>
 <dd>Contains the <em>preferred</em> count of characters that a line should have. Though technically still implemented, this attribute has no visual effect; to achieve such an effect, use CSS {{Cssxref("width")}} instead.</dd>
 <dt>{{htmlattrdef("wrap")}} {{non-standard_inline}}</dt>
 <dd>Is a <em>hint</em> indicating how the overflow must happen. In modern browser this hint is ignored and no visual effect results in its present; to achieve such an effect, use CSS {{Cssxref("white-space")}} instead.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<pre class="brush: html">
&lt;!-- Some example CSS code --&gt;
&lt;pre&gt;
body {
  color:red;
}
&lt;/pre&gt; 
</pre>

<h3 id="Result">Result</h3>

<pre class="brush: css">
body {
  color:red;
}
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'grouping-content.html#the-pre-element', '&lt;pre&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>No significant change from {{SpecName("HTML WHATWG")}}</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'grouping-content.html#the-pre-element', '&lt;pre&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>No significant change from {{SpecName("HTML4.01")}}</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'struct/text.html#h-9.3.4', '&lt;dl&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>Deprecated the <code>cols</code> attribute</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>width</code></td>
   <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
   <td>{{CompatGeckoDesktop("1.0")}}<br />
    {{CompatGeckoDesktop("29.0")}}<sup>[1]</sup></td>
   <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
   <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
   <td>{{CompatVersionUnknown}}<sup>[1]</sup></td>
  </tr>
  <tr>
   <td><code>cols</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("1.0")}}<br />
    {{CompatNo}} {{CompatGeckoDesktop("29.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>wrap</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("1.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>width</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}}{{CompatGeckoMobile("29.0")}}<sup>[1]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>cols</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile("1.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>wrap</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Specifying the <code>width</code> attribute has no layout effect.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>CSS: {{Cssxref('white-space')}}, {{Cssxref('word-break')}}</li>
</ul>
Revert to this revision