HTML <plaintext> Tag

The <plaintext> tag was an early HTML element designed to display all content following it as raw, unformatted text. Unlike the <pre> tag, which allows for some basic formatting such as spaces and line breaks, the <plaintext> tag rendered everything literally. This included HTML tags, making it useful for displaying code examples, but also limiting its versatility. It is now deprecated and should be avoided in favor of more modern alternatives.

HTML Plaintext: Displaying Preformatted Text (Deprecated)

Syntax

<plaintext>
  Plain text content, including HTML tags and other special characters.
</plaintext>

Attributes

The <plaintext> tag does not support any specific attributes.

Example

<p>This is normal text.</p>
<plaintext>
  <p>This is inside the plaintext tag. All text, including tags will be rendered as is.</p>
  <strong>This text will also be displayed as plain text</strong>
  Line breaks and spaces       are preserved.
</plaintext>

More Examples

Basic Demonstration:

This example shows how the content within the <plaintext> tag is displayed as plain text in the browser, without interpreting HTML elements.

<!DOCTYPE html>
<html>
<head>
  <title>Plaintext Example</title>
</head>
<body>
  <p>Normal paragraph:</p>
  <p>This paragraph is rendered as expected.</p>

  <plaintext>
    <p>This is inside the plaintext tag and will be displayed as plain text.</p>
    <br>Line breaks are also not interpreted.
     This is on a new line with spaces.
  </plaintext>
</body>
</html>

Code Example Display (Historical):

The tag was sometimes (incorrectly) used to display code, but this was not its intended use and is better served using <pre> and <code> tags.

<!DOCTYPE html>
<html>
<head>
  <title>Plaintext Code Example (not recommended)</title>
</head>
<body>
  <p>Here is some sample code, though this use is not recommended:</p>
  <plaintext>
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Sample HTML&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Hello World!&lt;/h1&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </plaintext>

  <p>Use &lt;pre&gt; and &lt;code&gt; for code blocks instead.</p>
</body>
</html>

Browser Support

The <plaintext> tag has been deprecated and is not supported by modern browsers. Its behavior in older browsers may be inconsistent.

Browser Support
Chrome No
Edge No
Firefox No
Safari No
Opera No
Internet Explorer Yes (Very old versions)

Notes and Tips

  • Do not use: The <plaintext> tag is deprecated and should not be used in modern web development. It has inconsistent behavior across different browsers.
  • Alternatives: Use the <pre> tag in conjunction with the <code> tag for displaying preformatted text, including code. You can also apply CSS styling for better presentation.
  • Security: The <plaintext> tag does not sanitize the input which can cause security risks if used in areas where user-generated content may be present.
  • Legacy Code: If you encounter the <plaintext> tag in legacy code, you should replace it with the recommended alternatives for compatibility and security.
  • Semantic HTML: Use <pre> and <code> tags for code and text you want to be rendered literally. These tags provide semantic meaning and can be styled with CSS for optimal presentation.

In summary, the <plaintext> tag is a deprecated and obsolete element that should not be used. Stick to modern HTML practices and semantic elements for the best results.