views:

341

answers:

3

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

+13  A: 

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.

Jack Sleight
+2  A: 
andynormancx
+4  A: 

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.

Rene Saarsoo