JavaScript encodeURIComponent() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript encodeURIComponent() Function

❮ JavaScript Global Functions

Example

Encode a URI:

var uri = "https://w3schools.com/my test.asp?name=ståle&car=saab";
var res = encodeURIComponent(uri);
Try it Yourself »

Definition and Usage

The encodeURIComponent() function encodes a URI component.

This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #

Tip: Use the decodeURIComponent() function to decode an encoded URI component.


Browser Support

Function
encodeURIComponent() Yes Yes Yes Yes Yes

Syntax

encodeURIComponent(uri)

Parameter Values

Parameter Description
uri Required. The URI to be encoded

Technical Details

Return Value: A String, representing the encoded URI

❮ JavaScript Global Functions