Chameleon
Chameleon

Reputation: 10138

Should I use & in href="" or & is enough in HTML4 and HTML5?

Should I use & in href="" or & is enough in HTML4 and HTML5?

The most of browser not have problem with this but how it should be done?

<a href="?param1=1&param2=2">Call()</a>

Or

<a href="&quest;param1=1&amp;param2=2">Call()</a>

Upvotes: 3

Views: 245

Answers (1)

hobbs
hobbs

Reputation: 240049

&amp; is correct. The bare ampersand generally works because if a browser sees an & that isn't followed by a valid entity reference, it passes it through, but there's no reason you should count on this behavior in code, especially if you can't guarantee the contents of the thing following the &. In particular, it's forbidden for &foo; to appear where "foo" is an alphanumeric string that isn't valid named character (this is called an "ambiguous ampersand" in HTML5), and it's obviously undesirable for &foo; to appear where "foo" is a valid named character, because it will be parsed as that character.

See the relevant spec requirements: https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Upvotes: 5

Related Questions