w3c markup validator ampersand (&) error

13,246

Solution 1

for each & sign you got write & in your example it would be:

c91588793296e2?s=50&d=http%3A%2F%

Solution 2

Use & for literal ampersands, even in URLs.

http://htmlhelp.com/tools/validator/problems.html#amp

Solution 3

Replace with &

Solution 4

should be:

c91588793296e2?s=50&d=http%3A%2F%.

notice the &

I know it feels wonky, but ampersands have to be encoded as html entities, which are confusingly denoted with ampersands.

Share:
13,246

Related videos on Youtube

crodjer
Author by

crodjer

Programmer

Updated on June 04, 2022

Comments

  • crodjer
    crodjer over 1 year

    Is there any workaround for the w3c validation error for an & present in urls or some other place in HTML markup?
    It says:

    & did not start a character reference. (& probably should have been escaped as &.)

    The ampersand in my case is a part of a url for gravatar thumbnail. This is the problematic part of a url:

    c91588793296e2?s=50&d=http%3A%2F%.

  • Mathias Bynens
    Mathias Bynens almost 12 years
    Note that it is not always required to encode ampersands, although it’s probably easiest to just do it. See mathiasbynens.be/notes/ambiguous-ampersands.
  • kernel
    kernel over 11 years
    You can use a regexp detection to automatically add &s where missing: htmlOut = htmlOut.replaceAll("&(?![a-zA-Z]+;)", "&");
  • andreaconsole
    andreaconsole almost 10 years
    I have a login-with-facebook code that adds a lot of messy not encoded ampersands and creates validation errors. Should I really write code to correct the error of someone else? :/