15

I would like to include < and > inside of a text in HTML but I'm unable to because HTML doesn't understand that it's text.

Is there any way to put those symbols in HTML as a text and make the editor understand it ?

Example:

<div> <this is some text> </div>
Sarvan Kumar
  • 926
  • 1
  • 11
  • 27
Zack Roberto
  • 229
  • 1
  • 2
  • 10

5 Answers5

36

Yes, simple use &lt; and &gt; like this:

Use then &lt;like&gt; this

<br>
  
5 &lt; 6 = true

<br>
  
1 &gt; 2 = false

Your Example would be:

<div>&lt;this is some text&gt;</div>

They are called HTML Entity's:

An HTML entity is a piece of text ("string") that begins with an ampersand (&) and ends with a semicolon (;) . Entities are frequently used to display reserved characters (which would otherwise be interpreted as HTML code), and invisible characters (like non-breaking spaces)

You can check the full entity's list in W3 Org and learn more about it in the MDN Documentation

Matheus Cuba
  • 2,068
  • 1
  • 20
  • 31
11

Please have a look at html entities

enter image description here

You can use the entity names directly in your html.

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

likewise

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

Go and edit the Fiddle, try all the html entities and check the output

Syam Pillai
  • 4,967
  • 2
  • 26
  • 42
3

I haven't understood your answer but as I think you want to include < or > so here is the HTML code for that &lt; &gt;.

3

You Need to Escape Characters that would be seen as code:

The escape character for < is: &lt;

For a complete list of escape characters floow this link: https://www.freeformatter.com/html-entities.html

ArcherBoy27
  • 130
  • 1
  • 9
2

to print < you must write &lt; or &#60; and for > write &gt;

like you use &nbsp; for white-space

Paras
  • 240
  • 1
  • 13