HTML <listing> Tag

Beginner
5 min read
Updated: Oct 2026
3 examples
Obsolete

Definition and Usage

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.

HTML Syntax

syntax.html
<listing>legacy listing text</listing>

Modern equivalent: <pre><code>…</code></pre> (escape special characters in the text).

Attributes

<listing> had no useful element-specific attributes — only globals. Prefer modern replacements.

AttributeDescriptionTry it
(none required)Legacy bare <listing> with preformatted text — study onlyTry it
Use <pre>Correct today — preformatted block textTry it
Use pre + codeBest for source code; escape < and &Try it
Global attributesid, class, lang, and other globalsLegacy only

Global Attributes

The <listing> tag also supports the Global Attributes in HTML.

Live Preview

Compare legacy <listing> with modern <pre>. Prefer the modern markup for real pages.

markup style

Study only. New pages should always use <pre> (and <code> when needed).

Preview
line 1 indented line 2 line 3

Using obsolete <listing> — migrate to <pre>.

HTML Examples

Short snippets for study and migration. Use Try It Yourself for a live editor.

Example 1 — Legacy listing (Study Only)

Recognize old markup. Do not copy this into new projects.

HTML
<!-- Obsolete — for study only -->
<listing>
function hello() {
  return "Hi";
}
</listing>
Try It Yourself

How It Works

  1. Spot the tag name. <listing> wraps the block of text.
  2. Expect monospaced look and kept whitespace in old UAs.
  3. Treat as legacy. Valid for understanding old pages, not for new HTML.
  4. Plan a migrate to pre / code.

Example 2 — Migrate to pre

Same visual idea with the supported preformatted element.

HTML
<pre>
function hello() {
  return "Hi";
}
</pre>
Try It Yourself

How It Works

  1. Replace <listing> with <pre>.
  2. Replace the end tag </listing> → </pre>.
  3. Keep indentation in the source — pre preserves it.
  4. Ship pre in all new and updated pages.

Example 3 — Preferred: pre + code

Mark source code semantically, and escape HTML characters in the text.

HTML
<pre><code>if (x &lt; 10) {
  alert("ok");
}</code></pre>
Try It Yourself

How It Works

  1. Wrap with <pre> to keep layout.
  2. Add <code> when the text is computer code.
  3. Escape < as &lt; and & as &amp;.
  4. Avoid obsolete siblings like <xmp> for the same job.

Edge Cases & Pitfalls

The main risk is treating browser display as permission to keep shipping listing.

obsolete

Do not use in new HTML

Validators flag <listing>. Always author <pre> / <code>.

parsing

Not a safe raw-text box

Modern rendering may interpret markup inside. Escape characters in your pre/code replacement.

migration

Rename tags, keep whitespace

Swap to pre, then escape any < / & that should show as text.

siblings

Same story for xmp

<xmp> is also obsolete for this role — use pre + code.

CSS

Update selectors too

Rules targeting listing will miss migrated pre until you update the stylesheet.

Browser Support

<listing> is an obsolete HTML element. Prefer <pre> and <code> in every modern document.

✓ Obsolete · Legacy rendering

<listing>

Still displayed in many browsers for old content, but non-conforming for authors. Use pre/code for new work.

Legacy Author guidance
Google Chrome Renders (legacy)
Obsolete
Mozilla Firefox Renders (legacy)
Obsolete
Apple Safari Renders (legacy)
Obsolete
Microsoft Edge Renders (legacy)
Obsolete
Opera Renders (legacy)
Obsolete
Samsung Internet Renders (legacy)
Obsolete
Internet Explorer Supported (legacy)
Obsolete
<listing> Do not use in new pages

Bottom line: Rendering support is not a green light. Migrate to pre/code and treat listing as archive knowledge.

Key Takeaways

  • Status: <listing> is obsolete — study it, do not ship it.
  • Replacement: use <pre> and <code>.
  • Escape: write &lt; and &amp; for literal < and &.
  • CSS: update selectors from listing to pre when you migrate.

One line: recognize <listing>, replace it with <pre> / <code>.

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.

Use pre instead

Show preformatted text and code with supported HTML elements.

pre tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful