Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it valid to escape html in a href attribute?

Assuming I have the following link:

<a href='http://google.com/bla'>http://google.com/bla</a>

Is this one also valid?

<a href='http:&#x2F;&#x2F;google.com/bla'>http://google.com/bla</a>

It works in Firefox, but I'm not sure if this is standardized behavior. I hope the question isn't super dumb!

like image 519
le_me Avatar asked Sep 02 '25 06:09

le_me


1 Answers

Yes, it is perfectly valid to do that. In fact, the ampersand (&) character must be escaped into &amp; in order to be valid HTML, even inside the href attribute (and all attributes for that matter).

like image 187
animuson Avatar answered Sep 04 '25 21:09

animuson