Escape tags in html

安稳与你 提交于 2019-12-18 01:29:08

问题


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.



来源:https://stackoverflow.com/questions/692123/escape-tags-in-html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!