HTML5: which is better - using a character entity vs using a character directly?

mikemaccana picture mikemaccana · Mar 21, 2012 · Viewed 7k times · Source

I've recently noticed a lot of high profile sites using characters directly in their source, eg:

<q>“Hi there”</q>

Rather than:

<q>&ldquo;Hi there&rdquo;</q>

Which of these is preferred? I've always used entities in the past, but using the character directly seems more readable, and would seem to be OK in a Unicode document.

Answer

GolezTrol picture GolezTrol · Mar 21, 2012

If the encoding is UTF-8, the normal characters will work fine, and there is no reason not to use them. Browsers that don't support UTF-8 will have lots of other issues while displaying a modern webpage, so don't worry about that.

So it is easier and more readable to use the characters and I would prefer to do so.

It also saves a couple of bytes which is good, although there is much more to gain by using compression and minification.