Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the character "&" alone illegal in HTML 4.01 Strict documents?

Tags:

html

I always saw statements to not use & in HTML documents by itself, and use & instead.

So I tried putting & in the title and in the content of the page, but they validate:

http://topics2look.com/code-examples/HTML/ampersand-by-itself-can-validate.html

Is & by itself legal in HTML 4.01 Strict documents?

like image 547
nonopolarity Avatar asked Oct 11 '22 06:10

nonopolarity


1 Answers

The W3C HTML 4.01 Strict Charset section says

Four character entity references deserve special mention since they are frequently used to escape special characters:

* "&lt;" represents the < sign.
* "&gt;" represents the > sign.
* "&amp;" represents the & sign.
* "&quot; represents the " mark.

Authors wishing to put the "<" character in text should use "<" (ASCII decimal 60) to avoid possible confusion with the beginning of a tag (start tag open delimiter). Similarly, authors should use ">" (ASCII decimal 62) in text instead of ">" to avoid problems with older user agents that incorrectly perceive this as the end of a tag (tag close delimiter) when it appears in quoted attribute values.

Authors should use "&amp;" (ASCII decimal 38) instead of "&" to avoid confusion with the beginning of a character reference (entity reference open delimiter). Authors should also use "&amp;" in attribute values since character references are allowed within CDATA attribute values.

As it uses the word "should" instead of "must", I guess you can skip it and still validate.

But don't do that, because it will sometimes render oddly.

I actually had to escape a couple of the ampersands in my cut-paste of this quote to get SO to render the character entity text... ;-)

like image 152
Don Roby Avatar answered Dec 22 '22 14:12

Don Roby