WikiGalaxy

Personalize

HTML URL Encoding

What is URL Encoding?

URL encoding, also known as percent encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI). It replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.

Why Use URL Encoding?

URLs can only be sent over the Internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.

Common Encoded Characters

For example, spaces are encoded as "%20", and special characters like "&" are encoded as "%26".

How to Encode URLs?

In HTML, you can use JavaScript's encodeURIComponent() function to encode a URL.

Example of URL Encoding

Consider the URL: https://example.com/search?query=hello world. The encoded version would be: https://example.com/search?query=hello%20world.


let url = "https://example.com/search?query=hello world";
let encodedUrl = encodeURIComponent(url);
console.log(encodedUrl);
        

Decoding URLs

To decode an encoded URL, you can use JavaScript's decodeURIComponent() function.

Console Output:

https%3A%2F%2Fexample.com%2Fsearch%3Fquery%3Dhello%20world

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025