ItzJavaCraft ItzJavaCraft - 7 months ago 11
HTML Question

How to make code show up in a HTML paragraph?

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?

Answer

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>

Comments