<p>html comments meant to be read by the person reading the source are like <code>&lt;!-- Write your comments here --&gt;</code>
But sometimes we want to depict a html as it is, for example show <code>&lt;b&gt;</code> to the end user and do not interpret the elemnt. Why the need to express this as <code>&lt;pre&gt;&amp;lt;b&amp;gt;&lt;/pre&gt; </code>? Why not a less convoluted way of doing this?</p>

<comments>
Why hasn't html a simple way of showing html tags as they are?
CC BY-SA 4.0
2023-11-29T19:52:28.237Z
I don't understand what this question is asking. Do you want to know why HTML uses character entity escapes as opposed to something else, or why it uses escapes at all, or are you asking for alternatives?
Ginger
CC BY-SA 4.0
2023-11-29T19:55:27.370Z
@Ginger I think they're asking why there isn't some sort of tag for quoting and displaying raw HTML
rydwolf
CC BY-SA 4.0
2023-11-29T19:58:41.443Z
I think the answer is essentially: There isn't much desire for it. It's not often that someone is writing HTML by hand *and* wants a lot of HTML tags displayed. Most HTML is generated, which prevents this from even being much of an inconvenience. This is what I would recommend: Generate your HTML. Then you can have a function that will replace `<` with `&lt;` and `>` with `&gt;` which you can use whenever you want to display HTML tags in the result.
David Young
CC BY-SA 4.0
2023-11-29T20:12:47.467Z
You can do this with `<xmp>`, but it's deprecated.
dan04
CC BY-SA 4.0
2023-11-29T20:14:26.527Z
Most HTML is generated nowadays, but when the language was being designed in the first place it was almost all written by hand. But also, when the language was being designed in the first place, it wasn't designed for ease of presenting code.
kaya3
CC BY-SA 4.0
2023-11-29T21:28:24.153Z
Are you looking for the deprecated [<plaintext> tag](https://www.w3docs.com/learn-html/html-plaintext-tag.html)
mousetail 'he-him'
CC BY-SA 4.0
2023-11-29T22:00:44.663Z
I’m voting to close this question because it is based on a false premise ─ HTML does have multiple ways to achieve this, so there is no design rationale needed for why it doesn't.
kaya3
CC BY-SA 4.0
2023-11-29T22:36:48.770Z
That isn't correct, though; `<xmp>` is long-deprecated & removed from the specification (and *why* would make a good component of an answer); contra the current top answer, CDATA sections have never been supported in text/html; plain-text scripts displayed inline are a hack for a Stack Overflow answer, not a design rationale answer for here; any contrast between the parsing requirements for `<xmp>` (gone) and `<script>` (present) would also support an answer.
Michael Homer
CC BY-SA 4.0
2023-11-30T01:27:54.250Z
Doesn't HTML DOM have a text node system?
Someone
<p>HTML actually does support what you want, via the <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/xmp" rel="nofollow noreferrer"><code>xmp</code></a> tag:</p>
<pre class="lang-html prettyprint-override"><code>&lt;xmp&gt;John Smith &lt;foo bar baz /&gt;&lt;/xmp&gt;
</code></pre>
<p>However, <code>xmp</code> is deprecated, has inconsistent implementation across browsers, and may be removed in future versions. Considering HTML <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode" rel="nofollow noreferrer">goes to great lengths to preserve backwards-compatibility (quirks mode)</a>, you can <em>probably</em> get away with it and your site will work on the major browsers for a long time (though any parsing library will probably fail unless it's especially compliant); but if at all possible, you should just escape the text and use <code>&lt;pre&gt;</code> instead.</p>
<h1>Why isn't it (officially, reliably) supported?</h1>
<p>HTML is very old, and the original format (arguably) had many oversights including this.</p>
<p>To change HTML to support unescaped text today, we'd have to get all major browsers to agree to a standard. Doing so will make outdated browsers fail to parse the new strings/delimiters, and outdated websites may break if they accidentally encode them. Browser maintainers don't like breaking outdated versions and websites, as evidenced by backwards-compatible quirks like the aptly-named <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode" rel="nofollow noreferrer">&quot;quirks mode&quot;</a>.</p>
<p>Furthermore, as David Young mentioned, there isn't much desire. You can already represent the text simply by escaping it, and most people aren't writing HTML by hand anyways, they're using HTML generators and template engines which escape the text for you.</p>
<p>So the simple reason is, <strong>the original designers of HTML must have overlooked or not cared about unescaped text, and once HTML became mainstream, there's never been enough movement to make the huge changes necessary.</strong></p>
<h1>How could it be supported</h1>
<h2>Via <code>CDATA</code></h2>
<p><a href="https://en.wikipedia.org/wiki/CDATA" rel="nofollow noreferrer"><code>CDATA</code></a> part of <a href="https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction" rel="nofollow noreferrer">XML</a>. It may even work if you make your webpage into <a href="https://developer.mozilla.org/en-US/docs/Glossary/XHTML" rel="nofollow noreferrer">XHTML</a>, which is basically HTML modified to be valid XML. However, like <code>xmp</code>, XHTML is also deprecated and <a href="https://softwareengineering.stackexchange.com/a/149843">attempts at modernizing it abandoned</a>.</p>
<pre class="lang-xml prettyprint-override"><code>&lt;![CDATA[John Smith &lt;foo bar baz /&gt;]]&gt;
</code></pre>
<h2>Via <a href="https://en.wikipedia.org/wiki/Here_document" rel="nofollow noreferrer">here strings</a></h2>
<p>Another way that HTML could represent truly unescaped text, is using here strings. Here strings let you specify an arbitrary close delimiter, so technically, any possible text can be unescaped within the string and it will not break out; <code>xmp</code> can't encode <code>&lt;/xmp&gt;</code>, and <code>CDATA</code> can't encode <code>]]&gt;</code>, because those are the closing delimiters.</p>
<p><strong>Example 1:</strong></p>
<pre><code>&lt;&lt;END
Foo bar &quot;baz&quot;
qux
END
</code></pre>
<p>Unquotes to</p>
<pre><code>Foo bar &quot;baz&quot;
qux
</code></pre>
<p><strong>Example 2</strong> (string containing &quot;END&quot;):</p>
<pre><code>&lt;&lt;END2
Foo
END
END2
</code></pre>
<p>Unquotes to</p>
<pre><code>Foo
END
</code></pre>
<p><strong>Example 3</strong> (string containing &quot;END&quot; and &quot;END2&quot;):</p>
<pre><code>&lt;&lt;END3
END END2
Foo
END3
</code></pre>
<p>Unquotes to</p>
<pre><code>END END2
Foo
</code></pre>
<p>and so on.</p>

CC BY-SA 4.0
2023-11-29T20:16:16.793Z
2023-11-30T01:09:44.653Z
2023-11-30T01:09:44.653Z
tarzh
CC BY-SA 4.0
2023-11-29T20:35:05.433Z
I think this would answer the question more if it touched on *why* `<xmp>` was deprecated - that would directly answer it as asked. I am inclined to think everything about heredocs is not relevant, but noting that XHTML supported `<![CDATA[` blocks would help in that section too.
Michael Homer
CC BY-SA 4.0
2023-11-29T22:18:57.157Z
I don't think `<![CDATA[ ... ]]>` *is* supported in HTML in any current browser; it will just be discarded as an invalid tag that wasn't understood.
Michael Homer
<p>Posting this as a community wiki since it's not really an answer.</p>
<p>You can abuse a <code>&lt;script&gt;</code> or <code>&lt;style&gt;</code> tag to get the effect you require:</p>
<pre><code>&lt;script style=&quot;display: inline&quot; type=&quot;text/plain&quot;&gt;
    &lt;h1&gt;Hello&lt;/h1&gt;
&lt;/script&gt;
</code></pre>
<p>Renders literally <code>&lt;h1&gt;Hello&lt;/h1&gt;</code> and does not interpret any HTML in the middle. This uses entirely modern HTML and is up to date with recent standards, though that does not make this less of a terrible hack.</p>
<p>If the text contains the literal text <code>&lt;/script&gt;</code> anywhere it will break out though so be careful inserting any untrusted strings, or you will have a nasty XSS vulnerability.</p>
<p>Tested in most modern browsers.</p>
<p>Use with caution.</p>

CC BY-SA 4.0
2023-11-29T21:38:16.290Z
2023-11-29T21:38:16.290Z
mousetail 'he-him'
# Why hasn't html a simple way of showing html tags as they are?
Posted by: username_0 on 2023-11-29
html comments meant to be read by the person reading the source are like 
But sometimes we want to depict a html as it is, for example show  to the end user and do not interpret the elemnt. Why the need to express this as <b> ? Why not a less convoluted way of doing this?
**Tags:** comments
> **Comments:**
> **username_1**: I don't understand what this question is asking. Do you want to know why HTML uses character entity escapes as opposed to something else, or why it uses escapes at all, or are you asking for alternatives?  
> **username_2**: @Ginger I think they're asking why there isn't some sort of tag for quoting and displaying raw HTML  
> **username_3**: I think the answer is essentially: There isn't much desire for it. It's not often that someone is writing HTML by hand *and* wants a lot of HTML tags displayed. Most HTML is generated, which prevents this from even being much of an inconvenience. This is what I would recommend: Generate your HTML. Then you can have a function that will replace `<` with `&lt;` and `>` with `&gt;` which you can use whenever you want to display HTML tags in the result.  
> **username_4**: You can do this with `<xmp>`, but it's deprecated.  
> **username_5**: Most HTML is generated nowadays, but when the language was being designed in the first place it was almost all written by hand. But also, when the language was being designed in the first place, it wasn't designed for ease of presenting code.  
> **username_6**: Are you looking for the deprecated [<plaintext> tag](https://www.w3docs.com/learn-html/html-plaintext-tag.html)  
> **username_5**: I’m voting to close this question because it is based on a false premise ─ HTML does have multiple ways to achieve this, so there is no design rationale needed for why it doesn't.  
> **username_7**: That isn't correct, though; `<xmp>` is long-deprecated & removed from the specification (and *why* would make a good component of an answer); contra the current top answer, CDATA sections have never been supported in text/html; plain-text scripts displayed inline are a hack for a Stack Overflow answer, not a design rationale answer for here; any contrast between the parsing requirements for `<xmp>` (gone) and `<script>` (present) would also support an answer.  
> **username_8**: Doesn't HTML DOM have a text node system?  
---
## 2 answers
### Answer by username_6 on 2023-11-29. Score: 3
Posting this as a community wiki since it's not really an answer.

You can abuse a 

Renders literally `# Hello` and does not interpret any HTML in the middle. This uses entirely modern HTML and is up to date with recent standards, though that does not make this less of a terrible hack.

If the text contains the literal text  anywhere it will break out though so be careful inserting any untrusted strings, or you will have a nasty XSS vulnerability.

Tested in most modern browsers.

Use with caution.
---
### Answer by username_9 on 2023-11-29. Score: 2
HTML actually does support what you want, via the xmp tag:
John Smith 

However, xmp is deprecated, has inconsistent implementation across browsers, and may be removed in future versions. Considering HTML goes to great lengths to preserve backwards-compatibility (quirks mode), you can probably get away with it and your site will work on the major browsers for a long time (though any parsing library will probably fail unless it's especially compliant); but if at all possible, you should just escape the text and use  instead.
Why isn't it (officially, reliably) supported?
HTML is very old, and the original format (arguably) had many oversights including this.
To change HTML to support unescaped text today, we'd have to get all major browsers to agree to a standard. Doing so will make outdated browsers fail to parse the new strings/delimiters, and outdated websites may break if they accidentally encode them. Browser maintainers don't like breaking outdated versions and websites, as evidenced by backwards-compatible quirks like the aptly-named "quirks mode".
Furthermore, as David Young mentioned, there isn't much desire. You can already represent the text simply by escaping it, and most people aren't writing HTML by hand anyways, they're using HTML generators and template engines which escape the text for you.
So the simple reason is, the original designers of HTML must have overlooked or not cared about unescaped text, and once HTML became mainstream, there's never been enough movement to make the huge changes necessary.
How could it be supported
Via CDATA
CDATA part of XML. It may even work if you make your webpage into XHTML, which is basically HTML modified to be valid XML. However, like xmp, XHTML is also deprecated and attempts at modernizing it abandoned.
John Smith <foo bar baz />

Via here strings
Another way that HTML could represent truly unescaped text, is using here strings. Here strings let you specify an arbitrary close delimiter, so technically, any possible text can be unescaped within the string and it will not break out; xmp can't encode , and CDATA can't encode ]]>, because those are the closing delimiters.
Example 1:
<
Unquotes to
Foo bar "baz"
qux

Example 2 (string containing "END"):
<
Unquotes to
Foo
END

Example 3 (string containing "END" and "END2"):
<
Unquotes to
END END2
Foo

and so on.
> **Comments:**
> **username_7** (2023-11-29): I think this would answer the question more if it touched on *why* `<xmp>` was deprecated - that would directly answer it as asked. I am inclined to think everything about heredocs is not relevant, but noting that XHTML supported `<![CDATA[` blocks would help in that section too.  
> **username_7** (2023-11-29): I don't think `<![CDATA[ ... ]]>` *is* supported in HTML in any current browser; it will just be discarded as an invalid tag that wasn't understood.  
---
