233

How can I escape the # hash sign (sometimes known as number sign or pound sign) sent in the query string of a URL?

0

1 Answer 1

394

Percent encoding. Replace the hash with %23.

4
  • Useful if you want to share a url which contains '#' to twitter Apr 5, 2018 at 2:13
  • 5
    This doesn't work on Chrome 74. Furthermore, encodeURI('#'); is returning # and not the percent encoded character May 20, 2019 at 12:10
  • 28
    # is a valid URI character, but it starts the hash fragment, so you need to encode it in the query string. Compare encodeURIComponent('#'). What do you see in Chrome 74? May 21, 2019 at 14:48
  • 1
    You must also encode a # anywhere in a data: URL, otherwise it will be treated as a fragment identifier.
    – Denis Howe
    Dec 12, 2022 at 19:20

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.