Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape tags in html

Here are some common entities. You do not need to use the full code - there are common aliases for frequently used entities. For example, you can use < and > to indicate less than and greater than symbols. & is ampersand, etc.

EDIT: That should be - &lt; &gt; and &amp;

EDIT: Another common character is &nbsp which is often used to represent tabs in <code> segments


How do these work?

Anything &#num; is replaced with character from ASCII table, matching that num.

Is that hex, or what is it?

It's not hex, the number represents characters number in decimal in ASCII table. Check out ASCII table. Check Dec and HTML columns.

Why aren't they just the characters themselves?

Look at this example:

<div>Hey you can use </div> to end div tag!</div>

It would mess up the interpreter. It's a bad example, but you got the idea.

Why you can't use escape characters like in programming languages?

I don't have exact answer to that. But html same as xml is a markup language and not programming language and answer probably lies within history of how markup languages become what they are now.


No, it's not hex, it's decimal. Hex equivalent is &#x3c; But one usually uses &lt; (less-than) for < and &gt; for > instead.


Here is the complete reference of html entities:

Complete HTML Entities

It is use for correct character formatting

HTML has a set of special characters which browsers recognize as part of the HTML language itself. For example, browsers know that when they encounter a < character in the HTML code, they are to interpret it as a beginning of a tag. > is one of an example of reserved character. Therefore use html character to avoid any problem and for correct practice also