4

I want to display HTML code as it is without rendering.

Current Output

Note : Use
for Line Break.

Expected Output

Note : Use <br> for Line Break.

<html>
<head>
</head>
<body>
  Note : Use <br> for Line Break.
</body>
</html>

4
  • 1
    Try using a <pre> Commented Sep 11, 2021 at 5:42
  • @Pieterjan I have tried but not working. Commented Sep 11, 2021 at 5:44
  • 1
    Does the html text come from a database or similar, or do you just want to show <br>? Otherwise you can use &lt;br&gt;... Commented Sep 11, 2021 at 5:48
  • Does this answer your question? Display HTML snippets in HTML Commented Sep 11, 2021 at 5:54

3 Answers 3

7

Method 1


You can use <xmp> but it's deprecated as suggested by @Someone_who_likes_SE. So probably avoid using it.

Mozilla XMP Documentation states:

The HTML element renders text between the start and end tags without interpreting the HTML in between and using a monospaced font.

<html>
<body>
  <xmp>Note : Use <br> for Line Break.</xmp>
</body>
</html>

Method 2


We generally replace the tag brackets with their HTML entities codes

< becomes &lt; and > becomes &gt;

<html>
    <body>
      Note : Use &lt;br&gt; for Line Break.
    </body>
    </html>

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

2 Comments

XMP is deprecated as of HTML 3.2 and was removed in HTML 5. Don't use it.
I know its deprecated but <xmp> is the only thing that works if someone does not or cannot use &lt; etc.
2

You can show HTML tags as plain text in HTML on a website or webpage by replacing < with &lt; or &60; and > with &gt; or &62; on each HTML tag that you want to be visible. Ordinarily, HTML tags are not visible to the reader on the browser.

Also you can look into this question: Display HTML snippets in HTML

Comments

1
Note : Use &lt;br&gt; for Line Break.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.