How to display tags like <html> in html page? | Sololearn: Learn to code for FREE!

+2

How to display tags like <html> in html page?

<!DOCTYPE html> <html> <head> <title>hello</title> </head> <body> <p><html> <head> <title>PHP Test</title> </head> <body> <p>Hello world </p> </body> </html> </p> </body> </html>

1/12/2018 7:40:32 AM

Bhaskarasai Chitturi

2 Answers

New Answer

+4

You have to replace at least '<' characters with html entities ( '<' is '&lt;' ) to avoid tags to be parsed intead be displayed... You also need to replace at least '&' ( '&amp;' ) to avoid html entities to be parsed and displayed as the charater they represent ;) However, you need to use a good suited container, or style it, for getting expected behaviour of displaying line break as in the source code, and not as default html content behaviour (line break are treated as spaces, and must be explicitly specified by introducing some <br> tags, and multi spaces are collapsed). Example: <pre><code>&lt;html> &lt;head> &lt;title>PHP Test&lt;/title> &lt;/head> &lt;body> &lt;p>Hello world &lt;/p> &lt;/body> &lt;/html> </code></pre> <pre> is a block container default styled to preserve text formating (line breaks, multi-spaces, tabulations...) <code> is an inline container default styled with monospaced font, usually used to display source codes... Try replacing them with a basic <p> or <div> to see how different is the behaviour ;) (you can also try to introduce <br>s to force line-breaks, and &nbsp; to force no collapsable spaces ^^ )

+2

You use the tag <code> to show blocks of code on your webpage.