JDelage
JDelage

Reputation: 13682

HTML tag to prevent HTML tags to be executed?

Basic question which I thought of asking on Superuser, but it is a programming question I think. I just started learning HTML, so please bear with me.

How can I prevent a program from interpreting an HTML tag / syntax? For example, I want to write a flash card like this:

The html code for < is &lt;

I would like a solution that would work for any or most syntax, not just for <.

How can I enter the syntax (without any space) to make sure the code isn't interpreted?

Upvotes: 9

Views: 12666

Answers (9)

Esteban K&#252;ber
Esteban K&#252;ber

Reputation: 36852

You are going to have to do it manually.

Here you have the full encoding table. The most commonly used codes are:

Character  Entity Number  Entity Name  Description
"          &#34;          &quot;       quotation mark
'          &#39;          &apos;       apostrophe (does not work in IE)
&          &#38;          &amp;        ampersand
<          &#60;          &lt;         less-than
>          &#62;          &gt;         greater-than

Upvotes: 9

irvnriir
irvnriir

Reputation: 826

<textarea readonly rows="2" cols="50" style="border:none; color:lightGray; background-color:black;">
<<line1>>
<<line2>>
</textarea>

is the only supported option . but its not enabled neither here neither on GitHub .

i'm 5min with HTML, so also would appreciate anyone enhancing it with dynamic size, achieved trough the tag's HTML/CSS attributes, or, if its not possible, trough a small embed Java Script .

Upvotes: 0

Rubens Farias
Rubens Farias

Reputation: 57976

In this case, you DON'T need to encode it. Try this one:

<xmp> html < &lt; </xmp>

I'm not sure about cross browsers support, but works on IE7,FF3,Chrome3

Upvotes: 7

Daan
Daan

Reputation: 6994

If you have access to server side scripting capabilities, you might be able to use utility functions of that platform. For example, in PHP you might use the htmlentities function to your advantage:

echo htmlentities("The html code for < is &lt;");

Upvotes: 1

NawaMan
NawaMan

Reputation: 25677

You need to encode it. For example, '<' = '&lt;'

Here is the list.

So in your case it will end up like this:

The html code for &lt; is &amp; l t ;

Upvotes: 0

Daniel Martin
Daniel Martin

Reputation: 23558

This:

The html code for &lt; is &amp;lt;

Renders as:

The html code for < is &lt;

The basic strategy is to escape the & as &amp;

Upvotes: 10

rsp
rsp

Reputation: 23373

You could use a <pre> &lt; </pre> sequence

Upvotes: 0

Fabian Vilers
Fabian Vilers

Reputation: 2982

I suppose you don't want the entity to be rendered? If you want to display &lt; you'll have to use the entity for the ampersand: &amp;.

Upvotes: 4

Sinan &#220;n&#252;r
Sinan &#220;n&#252;r

Reputation: 118156

The html code for < is &lt;

That is, type &lt; is &amp;lt;.

Upvotes: 1

Related Questions