Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

&nbsp causes a HTML5 validation fail

I'm in the process of applying a "HTML4.5" approach to an existing XHTML1.0 Strict site. The idea is to change the doctype and apply semantic classes matching the new elements of HTML5 (<div class="aside">, etc.) and do all that I can get away with, without Internet Explorer(IE) breaking (e.g. applying new <input> type attributes).

The only problem I've encountered is that W3C's validator doesn't like &nbsp; or &copy;, while html5.validator.nu has no problem.

I know that HTML5 validators are experimental at this stage. Should I replace &nbsp; with something? If so, what?

My charset on this particular site is UTF-8.

like image 836
isNaN1247 Avatar asked Nov 08 '10 20:11

isNaN1247


2 Answers

&nbsp; is fine in the text/html HTML5 and it validates for me at W3.

Where it won't validate is in XHTML5. The only built-in entities in XML are &amp;, &lt;, &gt;, &quot; and &apos;. XHTML1 brought in the HTML entity list by means of the DTD referenced by <!DOCTYPE>, but (X)HTML5 no longer uses a DTD, so that means in the XML serialisation you can't use the HTML entities.

A character reference such as &#xA0; is still okay. And if you're serving your page in the right encoding you can just include a U+00A0 No-Break Space character directly without escaping:  . (Of course that's going to be annoying to edit if your text editor doesn't visually distinguish the no-break and standard space.)

like image 85
bobince Avatar answered Nov 17 '22 21:11

bobince


Simply replace all the &nbsp; with &#160;

like image 1
Mehedi Avatar answered Nov 17 '22 22:11

Mehedi