mr x
mr x

Reputation: 77

How can i get typed code in output html in html?

How to get typed code in output in html?

I have code that I want to insert in the same way inside the html tag and display in the same way.

<body>
  <code>
    <script>alert("hey!");</script>
  </code>
</body>

I have the above and I expect my html output to be as follows. And this code is typed in the output, not executed!

<script>alert("hey!");</script>

Upvotes: 1

Views: 62

Answers (2)

ild flue
ild flue

Reputation: 1371

&lt;script>alert("hey!");&lt;/script>

Just use &lt; for the < at the beginning of a tag.

<body>
  <code>
    &lt;script>alert("hey!");&lt;/script>
  </code>
</body>

Upvotes: 1

QSan
QSan

Reputation: 11

You can use special symbols like this

< -> &lt;/&#60;
> -> &gt;/&#62;
& -> &#38;
# -> &#35;
( -> &#40;
) -> &#41;
" -> &#39;/&#34;/&quot;
$ -> &#36;
/ -> &#47;
\ -> &#92;
] -> &#93;
[ -> &#91;

Upvotes: 1

Related Questions