0

I'm using the <pre> tag for displaying source code on a website and now need to display some HTML. I don't want the user's browser to translate and display the HTML as HTML code, but simply display the source code.

How can I display HTML source code in a <pre> tag (or equivalent) within a HTML website?

Thanks in advance.

Alex K.
  • 171,639
  • 30
  • 264
  • 288
Tom Bell
  • 489
  • 2
  • 6
  • 15

2 Answers2

1

You'll have to use &lt; and &gt; instead of < and > respectively and browser will not consider it has html and hence will not render it. They are called as HTML Entities.

You can find and replace them or use many online services that does that for you.

Amit Joki
  • 58,320
  • 7
  • 77
  • 95
-1

Use the HTML tag <code> for your snippet.

Here's more on the subject <code> vs <pre> vs <samp> for inline and block code snippets

Community
  • 1
  • 1
Caelea
  • 2,318
  • 15
  • 22