0

I want to be able to make code show up on my website so that it shows up with the code on the webpage instead of using it as code in the HTML file itself.

Example:

<!DOCTYPE html>
<html>
  <body>
  <p>Hello World</p>
  </body>
</html>

Instead of:

Hello World

I know I explained that horribly but I'm sure you can see where I'm coming from. Can you escape in HTML? Or is there a tag that allows for HTML code to be viewed as text on a webpage?

ItzJavaCraft
  • 91
  • 12
  • Possible duplicate of [Display HTML code in HTML](http://stackoverflow.com/questions/2820453/display-html-code-in-html) – Persijn Apr 17 '16 at 15:10

3 Answers3

4

xmp tag

<!DOCTYPE html>
<html>
  <body>
  <xmp><p>Hello World</p></xmp>
  </body>
</html>

keep in mind that xmp tag is considered obsolete, as far as I know it is still supported by most browser but your mileage may vary.

you are safer if you use <pre> and escape html code with &lt; and &gt; like this

<!DOCTYPE html>
<html>
  <body>
      <pre>&lt;p&gt;Hello World&lt;/p&gt;</pre>
  </body>
</html>
Giuseppe
  • 846
  • 5
  • 10
1

There is similar question answered on this link: Display HTML code in HTML

In addition, have a look at the following websites

https://craig.is/making/rainbows

https://highlightjs.org/

Community
  • 1
  • 1
Michael Seltene
  • 543
  • 1
  • 5
  • 17
0

You can use the xmp property. Anything inside the xmp that is exempted by the browser while rendering the HTML code.

Example :

<xmp><h1>Heading</h1></xmp>
Rasik
  • 893
  • 1
  • 8
  • 30