Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why shouldn't `'` be used to escape single quotes?

As stated in, When did single quotes in HTML become so popular? and Jquery embedded quote in attribute, the Wikipedia entry on HTML says the following:

The single-quote character ('), when used to quote an attribute value, must also be escaped as ' or ' (should NOT be escaped as ' except in XHTML documents) when it appears within the attribute value itself.

Why shouldn't ' be used? Also, is " safe to be used instead of "?

like image 418
brad Avatar asked Jan 18 '10 03:01

brad


3 Answers

" is on the official list of valid HTML 4 entities, but ' is not.

From C.16. The Named Character Reference ':

The named character reference ' (the apostrophe, U+0027) was introduced in XML 1.0 but does not appear in HTML. Authors should therefore use ' instead of ' to work as expected in HTML 4 user agents.

like image 174
cletus Avatar answered Oct 07 '22 15:10

cletus


" is valid in both HTML5 and HTML4.

' is valid in HTML5, but not HTML4. However, most browsers support ' for HTML4 anyway.

like image 30
Zaz Avatar answered Oct 07 '22 15:10

Zaz


' is not part of the HTML 4 standard.

" is, though, so is fine to use.

like image 29
Anon. Avatar answered Oct 07 '22 14:10

Anon.