1

Is it valid html if a link looks like that:

<a href="http://www.example.com/home.php?a=2&b=5">example</a>

Or it should be:

<a href="http://www.example.com/home.php?a=2&#38;b=5">example</a>
Martin G
  • 17,357
  • 9
  • 82
  • 98
  • Both are valid, what are you trying to accomplish? – hd1 May 08 '13 at 22:03
  • 2
    No it's not. Why don't you [check it yourself](http://validator.w3.org/#validate_by_input+with_options)? – nice ass May 08 '13 at 22:04
  • @MartinSmith — Because it is a URL in an HTML document not a URL in a text document. – Quentin May 08 '13 at 22:11
  • One Trick Pony: You are right it says that "& did not start a character reference. (& probably should have been escaped as &.)". As I can see it accepts both & and & . Thank you! –  May 08 '13 at 22:13
  • Should I delete this question? –  May 11 '13 at 20:28

1 Answers1

1

The URL is a value in an HTML attribute, so the & character should be HTML encoded, most commonly using the HTML entity &amp;:

<a href="http://www.example.com/home.php?a=2&amp;b=5">example</a>

You can also use the HTML entity &#38; instead of &amp;.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005