&nbsp causes XHTML5 validation failure
Asked Answered
E

2

22

I'm in the process of applying an "HTML4.5" approach to an existing XHTML 1.0 Strict site in Internet Explorer. The idea is to change the Doctype and apply semantic classes matching the new elements of HTML (<div class="aside">, etc.) and do all that I can get away with, without Internet Explorer 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.

Evanescent answered 8/11, 2010 at 20:47 Comment(0)
C
32

&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.)

Colly answered 8/11, 2010 at 21:0 Comment(0)
D
1

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

Dicker answered 24/1, 2012 at 10:29 Comment(2)
i guess the correct decimal entity for &nbsp; should be &#160; or one could also use hexadecimal entity &#xa0;Incomprehensible
Some Other Useful HTML Character Entities - w3schools.com/html/html_entities.aspForeside

© 2022 - 2024 — McMap. All rights reserved.