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 589727 of <pre>

  • Revision slug: Web/HTML/Element/pre
  • Revision title: <pre>
  • Revision id: 589727
  • Created:
  • Creator: Dholbert
  • Is current revision? No
  • Comment Fix typo: s/hing/hint/

Revision Content

Summary

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

Attributes

This element only includes the global attributes.

{{htmlattrdef("cols")}} {{non-standard_inline}}{{deprecated_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 styling instead.
{{htmlattrdef("width")}} {{deprecated_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 styling 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 styling 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}}
No layout effect
{{CompatGeckoDesktop("1.0")}}
Layout effect removed in {{CompatGeckoDesktop("29.0")}}
{{CompatVersionUnknown}}
No layout effect
{{CompatVersionUnknown}}
No layout effect
{{CompatVersionUnknown}}
No layout effect
cols {{CompatNo}} {{CompatGeckoDesktop("1.0")}}
Removed in {{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")}}
Layout effect removed in {{CompatGeckoMobile("29.0")}}
{{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
cols {{CompatNo}} {{CompatGeckoMobile("1.0")}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
wrap {{CompatUnknown}} {{CompatGeckoMobile("1.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See also

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

Revision Source

<h2 id="Summary">Summary</h2>
<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 font exactly as it is laid out in the file. Whitespaces inside this element are displayed as typed.</p>
<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content_categories#Phrasing_content">Flow content</a>, palpable content.</li>
 <li><dfn>Permitted content</dfn> <a href="/en-US/docs/HTML/Content_categories#Phrasing_content" title="/en-US/docs/HTML/Content_categories#Phrasing_content">Phrasing content</a>.</li>
 <li><dfn>Tag omission</dfn> {{no_tag_omission}}</li>
 <li><dfn>Permitted parent elements</dfn> Any element that accepts <a href="/en-US/docs/HTML/Content_categories#flow_content" title="HTML/Content categories#flow content">flow content</a>.</li>
 <li><dfn>DOM interface</dfn> {{domxref("HTMLPreElement")}}</li>
</ul>
<h2 id="Attributes">Attributes</h2>
<p>This element only includes the&nbsp;<a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes" title="HTML/Global attributes">global attributes</a>.</p>
<dl>
 <dt>
  {{htmlattrdef("cols")}} {{non-standard_inline}}{{deprecated_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 styling instead.</dd>
 <dt>
  {{htmlattrdef("width")}} {{deprecated_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 styling 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 styling instead.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre class="brush: html">
&lt;!-- Some example CSS code --&gt;
&lt;pre&gt;
body {
&nbsp; color:red;
}
&lt;/pre&gt; 
</pre>
<h3 id="Result">Result</h3>
<pre>
body {
  color:red;
}
</pre>
<h2 id="Specifications" name="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" name="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}}<br />
     No layout effect</td>
    <td>{{CompatGeckoDesktop("1.0")}}<br />
     Layout effect removed in {{CompatGeckoDesktop("29.0")}}</td>
    <td>{{CompatVersionUnknown}}<br />
     No layout effect</td>
    <td>{{CompatVersionUnknown}}<br />
     No layout effect</td>
    <td>{{CompatVersionUnknown}}<br />
     No layout effect</td>
   </tr>
   <tr>
    <td><code>cols</code></td>
    <td>{{CompatNo}}</td>
    <td>{{CompatGeckoDesktop("1.0")}}<br />
     Removed in {{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")}}<br />
     Layout effect removed in {{CompatGeckoMobile("29.0")}}</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>
<h2 id="See_also">See also</h2>
<ul>
 <li>CSS: {{ Cssxref('white-space') }}, {{ Cssxref('word-break') }}</li>
</ul>
<div>
 {{ HTMLRef }}</div>
Revert to this revision