Escape tags in HTML
Asked Answered
W

5

51

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?

Wicker answered 28/3, 2009 at 3:26 Comment(0)
B
49

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

Borate answered 28/3, 2009 at 3:32 Comment(0)
C
37

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.

Cartel answered 28/3, 2009 at 3:35 Comment(2)
I think he means, why don't you just use \< to escape <, as in strings in many programming languages?Sanalda
NAh, I was just meaning why I couldn't use say < instead of the ascii. But I your example really explains. it. I guess it would confuse the browser. Thanks guys :DWicker
D
8

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

Deformation answered 28/3, 2009 at 3:31 Comment(0)
B
2

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

Bendicta answered 17/1, 2019 at 2:4 Comment(1)
Welcome to SO! This question is nearly 10 years old. You may want to look at some more recent questions here: stackoverflow.com/questions?sort=newestSluiter
E
0

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

Ed answered 28/3, 2009 at 3:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.