Escape tags in html

2019-03-22 15:53发布

问题:

What are escape tags in html?

Are they &#34; &#60; &#62; to represent " < >?
And how do these work?
Is that hex, or what is it?
How is it made, and why aren't they just the characters themselves?

回答1:

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.



回答2:

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



回答3:

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



回答4:

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



回答5:

Those escapes are decimal ascii escapes. You can see the values here. Take a look at the HTML column.