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.
Related videos on Youtube
Comments
-
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 almost 12 yearsNote 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 over 11 yearsYou can use a regexp detection to automatically add &s where missing:
htmlOut = htmlOut.replaceAll("&(?![a-zA-Z]+;)", "&");
-
andreaconsole almost 10 yearsI 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? :/