How do you escape less than symbol in html?

I'm trying to write a blog post which includes a code segment inside a <pre> tag. The code segment includes a generic type and uses <> to define that type. This is what the segment looks like:

<pre>
    PrimeCalc calc = new PrimeCalc();
    Func<int, int> del = calc.GetNextPrime;
</pre>

The resulting HTML removes the <> and ends up like this:

PrimeCalc calc = new PrimeCalc();
Func del = calc.GetNextPrime;

How do I escape the <> so they show up in the HTML?

How do you escape less than symbol in html?

VLAZ

24.2k9 gold badges45 silver badges61 bronze badges

asked Sep 3, 2008 at 17:41

2

<pre>
    PrimeCalc calc = new PrimeCalc();
    Func&lt;int, int&gt; del = calc.GetNextPrime;
</pre>

answered Sep 3, 2008 at 17:44

John SheehanJohn Sheehan

76.3k30 gold badges158 silver badges194 bronze badges

2

<pre>&gt;</pre>

renders as:

>

So you want:

<pre>
    PrimeCalc calc = new PrimeCalc();
    Func&lt;int, int&gt; del = calc.GetNextPrime;
</pre>

which turns out like:

    PrimeCalc calc = new PrimeCalc();
    Func<int, int> del = calc.GetNextPrime;

How do you escape less than symbol in html?

answered Sep 3, 2008 at 17:44

Use &lt; and &gt; to do < and > inside html.

How do you escape less than symbol in html?

dashtinejad

6,1464 gold badges28 silver badges44 bronze badges

answered Sep 3, 2008 at 17:43

crashmstrcrashmstr

27.7k8 gold badges64 silver badges79 bronze badges

&lt; and &gt; respectively

How do you escape less than symbol in html?

dashtinejad

6,1464 gold badges28 silver badges44 bronze badges

answered Sep 3, 2008 at 17:43

ckpwongckpwong

2,0591 gold badge17 silver badges17 bronze badges

How about:

&lt; and &gt;

Hope this helps?

answered Sep 3, 2008 at 17:43

toolkittoolkit

49k17 gold badges107 silver badges135 bronze badges

What rp said, just replace the greater-than(>) and less-than(<) symbols with their html entity equivalent. Here's an example:

<pre>
    PrimeCalc calc = new PrimeCalc();
    Func&lt;int, int&gt; del = calc.GetNextPrime;
</pre>

This should appear as (this time using exactly the same without the prepended spaces for markdown):

    PrimeCalc calc = new PrimeCalc();
    Func<int, int> del = calc.GetNextPrime;

answered Sep 3, 2008 at 17:48

akdomakdom

30.8k27 gold badges73 silver badges79 bronze badges

It's probably something specific to your blog software, but you might want to give the following strings a try (remove the underscore character): &_lt; &_gt;

answered Sep 3, 2008 at 17:43

OwenPOwenP

24.5k13 gold badges64 silver badges98 bronze badges

A better way to do is not to have to worry about the character codes at all. Just wrap all your code inside the <pre> tags with the following

<pre>
${fn:escapeXml('
  <!-- all your code -->
')};
</pre>

You'll need to have jQuery enabled for it to work, tho.

answered Dec 17, 2014 at 23:08

PanicBusPanicBus

5461 gold badge7 silver badges17 bronze badges

1

How do you escape less than HTML?

Less Than (<): It is reserved for use in tags (as in <div></div>). Thus, this character will have this specific meaning only. To escape them in <pre> tag tag, we need to use &lt; for HTML entity name or < for HTML entity number as a replacement.

How do I pass less than symbol in HTML?

Character entities are used to display reserved characters in HTML. &#entity_number; To display a less than sign (<) we must write: &lt; or &#60; Advantage of using an entity name: An entity name is easy to remember.

How do I escape the symbol in HTML?

Escaping HTML characters in a string means replacing the:.
less than symbol (<) with &lt;.
greater than symbol (>) with &gt;.
double quotes (") with &quot;.
single quote (') with &#39;.
ampersand (&) with &amp;.

How do you use greater than and less than symbols in HTML?

&lt; stands for lesser than (<) symbol and, the &gt; sign stands for greater than (>) symbol .