6

I'm thinking of names and stuff containing accented characters.

E.g.is there a difference between:

<a href="http://example.com/thing?name=forêt">link</a>

and

<a href="http://example.com/thing?name=for%C3%AAt">link</a>

?

Do browsers handle these the same? Or is there some compelling reason to encode these links?

2 Answers 2

5

Do browsers handle these the same?

Yes, all (modern) browsers handle these the same. In that all (modern) browsers implicitly URL encode (ie. percent-encode) the URL if you don't explicitly encode this yourself in the HTML source.

In both cases, the browser will implicitly request the percent-encoded URL when a user clicks the link. Select "Copy link address" from the browser's context menu and you copy the percent-encoded URL in both cases. Reading the href attribute of both links using JavaScript returns the percent-encoded URL.

In fact, I believe HTML5 allows unencoded unicode characters:
https://stackoverflow.com/a/19542940/369434

A potential problem might just be "old browsers". How old I don't know. But "old" might just be too old to worry about. (?)

1

W3C says URLs can only be sent over the Internet using the ASCII character-set. You will need to convert those characters to something. People often replace unsafe characters with their % encoded form. A percent-encoded reference can be found here.

Here is there reference: http://www.w3.org/Addressing/URL/4_URI_Recommentations.html

4
  • 2
    Yes, I know the recommendation. My question is more like is there a practical difference? AFAIK browsers can handle the unencoded form in my example just as well.
    – Tom
    Oct 29, 2015 at 20:59
  • "People often replace unsafe characters with % symbol." - you mean, invalid characters are percent-encoded.
    – MrWhite
    Oct 30, 2015 at 20:51
  • 1
    W3schools is NOT W3C. Nov 4, 2015 at 2:06
  • The link to W3schools is just for the % encoded reference chart. The reference at the bottom of my answer is directly to the W3C URI recommendations overview. Sorry for any confusion.
    – genepool99
    Nov 11, 2015 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.