1

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.

2
  • Google's Prettify javascript module is always an option. Commented Oct 7, 2014 at 15:37
  • do you want javascript to generate the source code view or a server side technology like php? Commented Oct 7, 2014 at 15:40

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.