Search code examples
htmlw3c-validationcarriage-return

Nu Html Checker Error "A numeric character reference expanded to carriage return." when using "
"


I want to use a carriage return in attribute title. And I have this HTML code:

<a href="javascript:;" title="Line 1 &#013;Line 2">Link Text</a>

But Nu Html Checker throws the error:

【Error】 A numeric character reference expanded to carriage return.

Also tried to use &#xD;, but got the same error.

I want to resolve this error, what can I do?


Solution

  • &#013; and &#xD; are numeric character references which escape the Unicode control character "CARRIAGE RETURN" (per UnicodeData.txt).

    In HTML, text (as in attribute values) must not contain control characters (other than space characters):

    The numeric character reference forms described above are allowed to reference any Unicode code point other than […] control characters other than space characters.

    According to the linked definition, "CARRIAGE RETURN" isn’t a space character.

    If you want a line break, you can use &#10;/&#xA;, which escape the Unicode control character "LINE FEED", but this one is defined to be a space character, so it’s allowed in text.

    <a href="javascript:;" title="Line 1&#10;Line 2">Link Text</a>
    
    <a href="javascript:;" title="Line 1&#xA;Line 2">Link Text</a>
    

    From the definition of the title attribute:

    If the title attribute’s value contains U+000A LINE FEED (LF) characters, the content is split into multiple lines. Each U+000A LINE FEED (LF) character represents a line break.

    Note that you could also add a line break like this:

    <a href="javascript:;" title="Line 1
    Line 2">Link Text</a>