JavaScript encodeURIComponent()

Example

Encode a URI:

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

Description

The encodeURIComponent() method encodes a URI component.

The encodeURIComponent() method encodes special characters including: , / ? : @ & = + $ #

Note

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

See Also:

The encodeURI() method to encode a URI

The decodeURI() method to decode a URI


Syntax

encodeURIComponent(uri)

Parameters

Parameter Description
uri Required.
The URI to be encoded.

Return Value

Type Description
A stringThe encoded URI.

Browser Support

encodeURIComponent() is an ECMAScript1 (ES1) feature.

ES1 (JavaScript 1997) is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.