plaintext element
plaintext is obsolete and never ends: everything after it, including the page's closing tags, becomes text; serve a text/plain file or use pre and code with the content escaped.
- Avoid
- Deprecated
- Severity
- DeprecatedFormally obsolete, but inert.
- Basis
- Obsoleted by the specA standard defined it, then removed it.
- Detectable
- YesMatched exactly. Autofixable when the rule carries a fix.
- Matches
plaintextElement rule, anywhere in the document.- Fix
- None — reports only
- Impacts
- Maintainability
- Related
element/xmp,element/listing
<plaintext> tells the browser to stop reading HTML. Everything after the start tag is shown as
typed, in a monospace font, to the end of the file. MDN traces it to HTML 2.
Why avoid
It is obsolete. The HTML Standard lists plaintext among the elements that “are entirely obsolete,
and must not be used by authors”, with the instruction: “Use the “text/plain” MIME type instead.”
Browsers still implement it, and it can’t be undone. The parser handles the start tag by switching
“the tokenizer to the PLAINTEXT state”, and the standard spells out what that means: “all remaining
tokens will be character tokens (and a final end-of-file token) because there is no way to switch
the tokenizer out of the PLAINTEXT state.” The PLAINTEXT state has no case for < or &, so
nothing after the start tag is markup:
- It has no end tag. Writing
</plaintext>just shows the characters</plaintext>. - The rest of the page becomes text.
</body>,</html>, a footer or a script after it all appear on screen as source code instead of doing anything. - Character references aren’t decoded.
&stays five characters.
What it adds in return is appearance only. The rendering section styles it like pre: a block, in
a monospace font, with white-space: pre.
Use instead
If the whole document is plain text, serve it as plain text. A .txt file with
Content-Type: text/plain is shown as typed, with no markup to escape.
To show text inside an HTML page, use pre and code, and escape < and &:
<pre><code>Line one <not a tag> & more</code></pre>
Detectability
Fully detectable by tag name, anywhere in the document: a <plaintext> written in <head> is moved
into <body> by a browser but not by every parser deadhead uses, so the rule doesn’t limit itself to
either. Nothing after the start tag is linted, because a browser reads it as text.
There is no autofix. Removing the start tag would turn the rest of the file back into markup, which
changes the page, and moving to pre and code means escaping the content.
Resources
- HTML Standard — Non-conforming features —
plaintextis obsolete; use thetext/plainMIME type instead. - HTML Standard — Parsing: the “in body” insertion mode — the start tag switches the tokenizer to PLAINTEXT, with no way back.
- HTML Standard — PLAINTEXT state — every character,
<and&included, is emitted as text. - HTML Standard — Rendering: flow content —
plaintextis displayed likepre. - MDN —
<plaintext>— obsolete; servetext/plain, or usepreorcodewith<,>and&escaped.
This page is generated from content/rules/element/plaintext.md, the same file the linter is built from. Think the rule is wrong, or that browsers moved on? Say so — that is the most useful issue you can file.