HTML <listing> Element

The <listing> element was an early HTML element used to display preformatted text while preserving spaces and line breaks from the source document. It was commonly associated with displaying listings, examples, and other text where the original formatting needed to remain visible.

Historical Syntax

Early HTML documents could contain markup similar to the following:

<listing>
Name        Price
Apples      $2.00
Oranges     $3.00
Bananas     $1.50
</listing>

Spaces and line breaks inside the <listing> element were preserved when the content was displayed. Browsers typically rendered the text in a fixed-width font. This code is shown for historical reference only and should not be used in modern HTML.

Attributes

The <listing> element did not have any standardized element-specific attributes. Its primary behavior came from preserving the whitespace and line breaks within its contents.

Historical Use

The <listing> element appeared during the early development of HTML and was intended for blocks of text where the original spacing was significant. This made it useful for simple listings, examples, tables created with spaces, and other material that depended on fixed formatting.

Unlike normal HTML text, where consecutive spaces are generally collapsed and source line breaks do not automatically create visible line breaks, text inside <listing> retained its original whitespace.

The element was similar in purpose to other early preformatted-text elements, including <pre> and the now-obsolete <xmp> element.

Why It Became Obsolete

The <listing> element became unnecessary because the <pre> element provides a standardized way to represent preformatted text. Maintaining multiple elements with similar purposes added complexity without providing a meaningful advantage.

The <pre> element remains part of modern HTML and can be combined with other elements, such as <code>, when the preserved text represents computer code. CSS can then control the font, spacing, overflow, and other visual characteristics.

The <listing> element is obsolete and non-conforming in modern HTML.

Modern Alternative

Use the <pre> element when spaces and line breaks are significant and should be displayed as they appear in the HTML source.

<pre>
Name        Price
Apples      $2.00
Oranges     $3.00
Bananas     $1.50
</pre>

When the preformatted content represents computer code, place a <code> element inside <pre>:

<pre><code>body {
  font-family: Arial, sans-serif;
  margin: 20px;
}</code></pre>
Play in Editor

Legacy Browser Support

Modern browsers may still recognize the <listing> element and display its contents as preformatted text for compatibility with older webpages. This legacy behavior does not make the element valid for use in modern HTML.

Existing <listing> elements should be replaced with <pre> when older HTML documents are updated.

For detailed legacy browser compatibility information, see Can I Use: HTML <listing> Element .

Use the <pre> element for preformatted text in modern HTML. The <code> element can identify computer code, while the obsolete <xmp> element was another historical method of displaying preformatted content.

Specifications

The <listing> element is listed as an entirely obsolete, non-conforming feature in the WHATWG HTML Living Standard . Authors should use <pre> for preformatted text instead.