Live Preview
Modern <pre><code> block (what you should use today):
function exampleFunction() {
return "Hello, World!";
}
By the end of this tutorial, you’ll understand what <listing> was for, why it is obsolete, and which modern tags to use instead.
Preformatted text and code in monospaced font.
Deprecated in HTML 4, removed from HTML5.
Despite the name, it never created ul/ol lists.
Modern replacement for preformatted blocks.
Inline snippets and combined code blocks.
Replace listing in legacy code with pre + code.
<listing> Tag?The listing element (<listing>) was an early HTML tag for displaying preformatted text — especially code listings. Text inside listing was rendered in a monospaced font with whitespace and line breaks preserved, similar to how <pre> works today.
Do not use <listing> in new projects. It was deprecated in HTML 4.01 and removed from HTML5. Some browsers still render it like <pre>, but behavior is not guaranteed.
The name listing refers to a “code listing” or text listing — not an HTML list like <ul> or <ol>. For actual lists, use <li> inside list containers.
Historically, listing wrapped preformatted content with opening and closing tags:
<listing>
Your preformatted text or code here.
</listing><pre> instead.| Pattern | Code Snippet | Status |
|---|---|---|
| Legacy listing | <listing>code</listing> | Obsolete |
| Preformatted block | <pre>code</pre> | Modern replacement |
| Inline code | <code>fn()</code> | Modern replacement |
| Code block | <pre><code>...</code></pre> | Best practice |
| Actual lists | <ul><li>...</li></ul> | Use for lists, not listing |
| Attributes | None | N/A |
<listing> vs <pre>| Feature | <listing> | <pre> |
|---|---|---|
| HTML5 status | Obsolete | Standard |
| Purpose | Legacy preformatted text | Preformatted text blocks |
| Whitespace | Preserved | Preserved |
| Browser support | Partial / legacy | Universal |
| Use today? | No | Yes |
<listing> vs List TagsDo not confuse listing with list elements — they are unrelated despite similar names:
| Tag | Purpose | Example use |
|---|---|---|
<listing> | Preformatted code/text (obsolete) | Legacy code display |
<ul> / <ol> | Structured lists | Navigation, steps, features |
<li> | Single list item | Each bullet or numbered entry |
<dl> | Description list | Terms and definitions |
The <listing> element did not define any specific attributes. Only global attributes applied in theory, but the entire element is obsolete:
None ObsoleteListing had no dedicated attributes. It simply wrapped preformatted content.
<listing>...</listing>Global attrs LegacyAttributes like class or id may have worked in old browsers but are irrelevant today.
class="legacy"For modern code blocks, style <pre> and <code> with CSS instead.
Legacy listing usage and the modern <pre> and <code> replacements you should use instead.
Modern <pre><code> block (what you should use today):
function exampleFunction() {
return "Hello, World!";
}In the past, listing displayed code blocks with fixed-width formatting. Do not use this in new projects.
<listing>
function exampleFunction() {
return "Hello, World!";
}
</listing>Replace every <listing> in legacy code with <pre> for blocks, <code> for inline snippets, or <pre><code> together for semantic code listings.
Use <pre> for preformatted text blocks that preserve whitespace.
<pre>
function exampleFunction() {
return "Hello, World!";
}
</pre>For short code mentions within a sentence, use <code>.
<p>Use the <code>console.log()</code> function to print messages.</p>Best practice for code blocks: nest <code> inside <pre> for semantics and styling.
<pre>
<code>
function exampleFunction() {
return "Hello, World!";
}
</code>
</pre>Style modern <pre> and <code> replacements instead of obsolete listing:
pre Block formattingcode Inline monospacewhite-space Preserve spacingoverflow-x Scroll long linespre {
background: #0f172a;
color: #e2e8f0;
padding: 1rem;
border-radius: 8px;
overflow-x: auto;
font-size: 0.875rem;
line-height: 1.6;
}
code {
font-family: ui-monospace, monospace;
}
p code {
background: #f1f5f9;
padding: 0.15rem 0.4rem;
border-radius: 4px;
}Styled pre + code block
const greeting = "Hello, World!";
console.log(greeting);Modern code presentation is more accessible than legacy listing:
<code> — screen readers can identify inline code snippets.<pre><code> — clearer structure than obsolete listing.overflow-x: auto so long lines do not break layout on small screens.Code or preformatted text placed inside <listing> tags.
Whitespace and line breaks were preserved like a typewriter layout.
Spec dropped the element; browsers map it to pre-like rendering for compatibility.
Modern tags give the same visual result with standard HTML5 semantics and full browser support.
The <listing> element is obsolete. Browsers may still render it similarly to <pre>, but it is not part of HTML5 and should not be used in production.
Most browsers treat listing like pre for backward compatibility, but the element is removed from the HTML5 specification.
Bottom line: Do not use <listing> in new code. Use <pre> and <code> for full HTML5 compliance and consistent behavior.
The <listing> tag is a relic of early HTML for displaying preformatted text and code. It is obsolete in HTML5 and must not appear in new projects.
Replace every listing with <pre> for blocks, <code> for inline snippets, or both together for semantic code listings. For actual content lists, use <ul>, <ol>, and <li>.
<pre><code> for code blocks<code> for inline code mentions<ul>/<ol> for actual lists<listing> in new HTML documents<listing>Bookmark these so you never confuse legacy listing with modern list or code tags.
Listing displayed fixed-width code blocks.
FoundationRemoved from HTML5 — do not use.
StatusName refers to code listings, not ul/ol.
ComparisonModern block replacement.
ReplacementInline and nested code snippets.
ReplacementBrowsers may map it to pre-like output.
Compatibility<pre> and <code> instead.ul, ol, and li for lists.<pre> for blocks, <code> for inline snippets, and <pre><code> together for code listings.<pre> for backward compatibility, but it is not standard HTML5.pre and code in new projects.Try pre, code, and pre+code replacements in the interactive editor.
6 people found this page helpful