4

I'm confused about the correct way to insert special typographic characters (like quotation marks and em dashes) when producing content that will be displayed on a web page. Is it better or preferred to type the actual unicode characters like this:

“Hello, World”

or to use entities for special characters:

“Hello, World”

Are there any risks associated with using either (specifically the risk of the user seeing some crazy character substitution), or are they truly equivalent?

2 Answers 2

6

Use the actual character.

The disadvantage to using entities is readability. Pop quiz: what does the following output?

†‹ some text ›

Without looking it up, I would have had no idea. Even if you did, you should consider that others reading your markup might not.

For the most part, there's no reason you shouldn't just use the actual character. To avoid any issues, be sure you're using UTF-8 everywhere. You want to be sure of the following:

  • The page is saved with UTF-8 encoding
  • The 'Content-Type' HTTP header specifies UTF-8 encoding
  • Data pulled from databases is saved with UTF-8 encoding
  • Database connections use UTF-8 encoding

There are some exceptions.

When to use escapes

Syntax characters. There are three characters that should always appear in content as escapes, so that they do not interact with the syntax of the markup. These are part of the language for all documents based on XML and for HTML.

  • &lt; (<)
  • &gt; (>)
  • &amp; (&)
5
  • 1
    (Not having it looked up!) 8224 is in hex something like 8192+8+24 ~ U+2020. One of the fixed spaces then? The other 2 are Single Angled Quotes, and I imagine people may have to look up that as well <😀>
    – Jongware
    Commented Sep 16, 2015 at 19:17
  • @Jongware you're right on the other two, but I'll give you half credit for good deductive reasoning for the dagger :) †‹ some text ›
    – JohnB
    Commented Sep 16, 2015 at 19:21
  • 3
    hmmmm..... I use entities.. I mean it's pretty easy to tell what &mdash; or &middot; are. And use of things like &raquo; or &amp; are pretty clear once you use them a few times. I've had clients complain about "odd characters" (the ? diamonds) when I don't use entities. I'm wondering now if it's more an issue with text provided from Microsoft Word and resaved as Plain Text incorrectly.
    – Scott
    Commented Sep 16, 2015 at 22:26
  • @Scott this happens to me constantly with Word when saving or copy/pasting plain text. Commented Sep 17, 2015 at 14:14
  • Oh yeah, @Scott Word will forever fill your text with invisible land mines.
    – Preston
    Commented Sep 20, 2015 at 17:29
1

Now, in html5 we do not use the ascii encode anymore, but the utf-8. If you define your encode as utf-8, and you also encode the file itself in it, you will have no problems. (an old editor can not encode in utf-8, but there are a lot of free programs that do)

After that, if you need it, lets say for some programming needs, you \escape it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.