Home > database >  How can i get typed code in output html in html?
How can i get typed code in output html in html?

Time:05-21

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>

CodePudding user response:

You can use special symbols like this

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

CodePudding user response:

&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>

  •  Tags:  
  • html
  • Related