The <listing> element once showed preformatted text (often a code listing) in a monospaced font, keeping spaces and line breaks.
Learn it only to recognize legacy pages and migrate them. For every new project, use <pre> and, when the content is source code, <code> — escaping < and & as needed.
Obsolete.
Do not use <listing> in new HTML. The HTML Standard lists it as non-conforming; replace it with <pre> and <code>.
Still rendered in many browsers.
Legacy support may look like <pre>, but content inside can still be parsed as HTML — not a safe “raw text” container.
Syntax
HTML Syntax
syntax.html
<listing>legacy listing text</listing>
Modern equivalent:<pre><code>…</code></pre> (escape special characters in the text).
Reference
Attributes
<listing> had no useful element-specific attributes — only globals. Prefer modern replacements.
Attribute
Description
Try it
(none required)
Legacy bare <listing> with preformatted text — study only
CSS: update selectors from listing to pre when you migrate.
One line: recognize <listing>, replace it with <pre> / <code>.
UA style
Default CSS Settings
Legacy engines often treated listing like a monospaced block. Prefer styling pre today:
default.css
/* Legacy recognition only */
listing {
display: block;
font-family: monospace;
white-space: pre;
}
/* Modern replacement */
pre {
display: block;
font-family: monospace;
white-space: pre;
}
Leave listing rules only while cleaning legacy CSS; author new styles for pre and code.
Frequently Asked Questions
No for new work. The listing element is obsolete. Authors must use pre (and code when the content is computer code) instead.
It displayed preformatted text — often code listings — in a monospaced font, preserving spaces and line breaks. Early specs suggested lines up to about 132 characters.
Use pre for preformatted text. Nest code inside pre when the content is source code. Escape < and & so they are not parsed as HTML.
Many browsers still render listing, often like pre. That is legacy behavior — not a reason to write new listing markup.
Do not rely on that. Modern agents may treat it like pre and interpret markup inside. Always escape special characters in replacements.
Both are obsolete preformatted / plaintext-style elements. The HTML Standard says use pre and code instead of listing or xmp.