Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are HTML encoded special characters required to end in a semicolon?

The correct encoding for em-dash is supposedly —, however when the semi-colon is left off it still displays correctly in my browers (chrome and firefox).

Furthermore, I'm using Litmus.com to test character encodings across several email clients. It turns out nearly all of them also ignore the required semicolon when displaying special characters with the exception of gmail (IE, chrome, and firefox).

So my question: Are encoded HTML special characters required to end in a semicolon? It seems like gmail is playing by the rules while everyone else ignores the required semi-colon.

like image 449
kburns Avatar asked Nov 01 '12 18:11

kburns


3 Answers

Since HTML up to version 4.01 is SGML based it is possible to eliminate the final ;, see w3centities.

Note. In SGML, it is possible to eliminate the final ";" after a character reference in some cases (e.g., at a line break or immediately before a tag). In other circumstances it may not be eliminated (e.g., in the middle of a word). We strongly suggest using the ";" in all cases to avoid problems with user agents that require this character to be present.

However, the current HTML5 working draft states that character references need to be terminated with a semicolon. In order to prepare your current sites for HTML5 I recommend you to end the references with a semicolon.

like image 169
Zeta Avatar answered Oct 05 '22 05:10

Zeta


Browsers do their best to interpret your intentions and are somewhat forgiving. It's best to stick to the rules to ensure things work properly everywhere.

like image 41
Diodeus - James MacFarlane Avatar answered Oct 05 '22 06:10

Diodeus - James MacFarlane


There have been several debates about the 'optional' semi-colon use-case. The best advice I can give you is to use it.

If the rule is using it causes ALL browsers to work and not using it causes MOST browsers to work, go with the ALL.

Plus, W3C states it here (though I can't find the full spec): http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.3

like image 39
Fluidbyte Avatar answered Oct 05 '22 07:10

Fluidbyte