Paul
Paul

Reputation: 101

Do we really need to replace & with &amp in URLs?

I am using a validation tool and it is returning errors that the page has parsing errors Found '&'. You should use '&amp;' instead found in php-style links (i.e. < a href="index.php?route=home&path=1"> is incorrect whereas < a href="index.php?route=home&amp;path=1"> is considered correct). What standards does this break? I thought it was normal practice to use & in URLs. The website is written in PHP.

Please note that I am not looking for support on the software. I'm just curious to know what part of the standards I may be breaking.

Upvotes: 1

Views: 5181

Answers (1)

Quentin
Quentin

Reputation: 943217

This has nothing to do with accessibility or URLs.

& is a special character in HTML which means "start of entity".

To say "An ampersand" instead of "Start of entity" in HTML you should use the entity for ampersand: &amp;.

There are times when you can use a raw & in HTML, but it is simplest to always use &amp; instead of trying to remember the times when it is optional.

(Exception: You must use a raw & are inside <script> and <style> elements.)

Upvotes: 4

Related Questions