motobói
motobói

Reputation: 1805

Should I still use html entities? Why?

Are HTML entities still useful or should I simply create UTF-8 encoded html documents? Please explain why.

Upvotes: 24

Views: 5139

Answers (3)

andynormancx
andynormancx

Reputation: 13742

In my experience as long as your data really is UTF-8 and you are correctly telling the browser that it is UTF-8 then you don't need to use entities. Except for things like >, <, &quot ; of course.

Upvotes: 6

Jack Sleight
Jack Sleight

Reputation: 17118

If the encoding is set correctly (and the document is saved as UTF-8) you should be able to work with just the characters. From the W3C:

Using an encoding such as UTF-8 means that you can avoid the need for most escapes and just work with characters.

http://www.w3.org/International/questions/qa-escapes

However, you still need to use entities for special characters such at greater/less than.

Upvotes: 31

Rene Saarsoo
Rene Saarsoo

Reputation: 13907

Entities are useful in program source code files (in programs that output HTML). Many coding standards say, that files should be in plain ASCII. Except of course the files that actually contain the textual content – for example .po files with translations.

When you have a long file with few non-ASCII characters inside, then it's extremely easy to save the file in wrong encoding without noticing that your characters got screwed.

Another good reason to use non-ASCII characters is similar-looking chracters. Can you spot the difference between the next two lines of code:

print "<title>" + pagename + " – " + sitename + "</title>";
print "<title>" + pagename + " - " + sitename + "</title>";

But by using entities the difference is obvious:

print "<title>" + pagename + " &ndash; " + sitename + "</title>";
print "<title>" + pagename + " - " + sitename + "</title>";

But outside of program source code files, UTF-8 is clearly the way to go.

Upvotes: 10

Related Questions