Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Best Practices: Should I use ’ or the special keyboard shortcut?

I know that ’ will produce an apostrophe in an HTML document.

I also know that option shift right bracket on a Mac will simply produce a character.

Are there best practices for writing code, e.g., should I write

<b>The User&rsquo;s Forum</b>

or

<b>The User’s Forum</b>

(note that by using the keyboard shortcut I've been able to type instead of ' above)

It strikes me that the latter (using the keyboard shortcut) is more robust, as it's not likely to display the raw HTML if, for example, it's not escaped.

On the other hand, the special ’ character may not be readable in some browsers, perhaps(?).

Anyone have any best practices on this?

like image 588
user2238214 Avatar asked Apr 02 '13 23:04

user2238214


4 Answers

I don't think that one is better than the other in general; it depends on how you intend to use it.

  • If you want to store it in a DB column that has a charset/collation that does not support the right single quote character, you may run into storing it as the multi-byte character instead of 7-bit ASCII (&rsquo;).
  • If you are displaying it on an html element that specifies a charset that does not support it, it may not display in either case.
  • If many developers are going to be editing/viewing this file with editors/keyboards that do not support properly typing or displaying the character, you may want to use the entity
  • If you need to convert the file between various character encodings or formats, you may want to use the entity
  • If your HTML code may escape entities improperly, you may want to use the character.

In general I would lean more towards using the character because as you point out it is easier to read and type.

like image 91
Explosion Pills Avatar answered Oct 03 '22 00:10

Explosion Pills


Typographically, the correct glyph to use in sentence punctuation is the quote mark, both single (including for apostrophes) and double quotes. The straight-looking mark that we often see on the web is called a prime, which also comes in single and double varieties and has limited uses, mostly for measurements.

This article explains how to use them correctly.

like image 32
jsring Avatar answered Oct 03 '22 02:10

jsring


With &rsquo; you know for certain that the output will be correct, no matter what.

I wish &apos; would output the proper apostrophe and not the typewriter apostrophe.

like image 26
Manuel Gutierrez Rojas Avatar answered Oct 03 '22 00:10

Manuel Gutierrez Rojas


You should only use &rsquo; if your intention is to make either a closed single quotation mark or an apostrophe. Both of these punctuation marks are curved in shape in most fonts. If your intent is to make a foot mark, go the other route. A foot mark is always a straight vertical mark.

It’s a matter of typography. One way is correct; the other is not.

like image 34
Lori123 Avatar answered Oct 03 '22 01:10

Lori123