35

How do I print the "html" tag, including '<' and '>'? How can I do this for any tag, without using text areas and Javascript?

Syam Pillai
  • 4,967
  • 2
  • 26
  • 42
Jagan
  • 4,649
  • 19
  • 60
  • 70
  • There are a few websites that automatically convert the special characters to their HTML equivalent. https://nrecursions.blogspot.com/2014/11/posting-html-css-and-javascript-code-in.html – Nav Sep 04 '19 at 06:48

10 Answers10

50

Use HTML character references:

&lt;html&gt;

Should output

<html>
driis
  • 161,458
  • 45
  • 265
  • 341
12

Special characters in HTML, such as '<', '>', '"' and '&' can be printed using the following format:

&name;

where name would be replaced by a character name. The most common would then be

&lt;   =   <    (less than)
&gt;   =   >    (greater than)
&amp;  =   &    (ampersand)
&quot; =   "    (double quote)

So to write <html> you would write in HTML:

&lt;html&gt;
Frxstrem
  • 38,761
  • 9
  • 79
  • 119
9

Try doing:

&lt;html&gt;
D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
4

If you want to display <html> literally, use reference to represent the tag open delimiter < and the tag close delimiter >, for example:

&lt;html&gt;

This will then be displayed as:

<html>

Gumbo
  • 643,351
  • 109
  • 780
  • 844
4

Please have a look at html entities

enter image description here

You can use the entity names directly in your html.

<p> &lt;html&gt; </p> will render as <html>.

likewise

<p> 3 &gt; 2 </p> will render as 3 > 2.

Try all the html entities and check the output in this Fiddle

Syam Pillai
  • 4,967
  • 2
  • 26
  • 42
  • 1
    Please [edit] to paste the text used in the image into your answer so that it can be read on all devices, edited, copied as text, and found through search. As it stands now, your image makes it hard to view and use your answer. See the [formatting documentation](/editing-help) for tips to make your text appear nicely without resorting to images. – Stephen Ostermiller Jan 19 '22 at 08:47
3

portrayal of linkTo put < and > characters in HTML, you have to input their corresponding character sequences. For example, <'s sequence is &lt; while >'s sequence is &gt;. If you replace all the < and > with their corresponding characters you will be able to present the HTML code in your website. However, this process can be a bit tedious. This is why there are tools on the internet that help you do this. For example:

  1. https://displayhtmlcode.pythonanywhere.com/ (A very simple website that does just what you need it to do.)
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
  • Do you have any affiliation with the linked website? This answer says the same thing as other answers, plus a link to a website which seems like it could be self-promotion to me. – Stephen Ostermiller Jan 19 '22 at 08:52
2

do this

&lt;html&gt;
Daniel Moura
  • 7,816
  • 5
  • 35
  • 60
-1
&lt;html&gt;

my output code <HTML>

SagarPPanchal
  • 9,839
  • 6
  • 34
  • 62
-1

To print an HTML tag write

&lt;html> 

or &lt;html&gt;

both gives the same output : <html>

MIM
  • 54
  • 5
-2

Best and easyest way:

 <xmp>
// your codes ..
</xmp>
human
  • 467
  • 4
  • 6