Percent Encoding Tool
Encode and decode text using percent encoding with our free online tool. Percent encoding (also called URL encoding) represents characters as %XX hexadecimal values, enabling safe transmission of any character through URL-restricted contexts.
Percent Encoding Reference
| Hex Value | Character | Category | %00-%1FControl charsNon-printable %20SpaceWhitespace %21!Reserved in some contexts %22"Unsafe %23#Fragment delimiter %25%Encoding character itself %2F/Path delimiter | %3F | ? | Query delimiter |
RFC 3986 Character Classes
The URL specification defines these character categories:
- Unreserved (never encoded): A-Z, a-z, 0-9, - . _ ~
- Reserved (encoded when not delimiters): : / ? # [ ] @ ! $ & ' ( ) * + , ; =
- Unsafe (always encoded): spaces, <, >, {, }, |, \, ^,
, and non-ASCII
Percent Encoding Implementation
`javascript
function percentEncode(text, options = {}) {
const { encodeReserved = true, charset = 'utf-8' } = options;
// Convert to UTF-8 bytes
const encoder = new TextEncoder();
const bytes = encoder.encode(text);
// Unreserved characters per RFC 3986
const unreserved = /[A-Za-z0-9\-._~]/;
let encoded = '';
for (const byte of bytes) {
const char = String.fromCharCode(byte);
if (unreserved.test(char)) {
encoded += char;
} else {
encoded += '%' + byte.toString(16).toUpperCase().padStart(2, '0');
}
}
return {
encoded,
byteCount: bytes.length,
encodedLength: encoded.length
};
}
// Strict RFC 3986 encoding
function rfc3986Encode(text) {
return encodeURIComponent(text).replace(/[!'()*]/g, c =>
'%' + c.charCodeAt(0).toString(16).toUpperCase()
);
}
``
Percent Encoding Standards
Different systems use slightly different percent encoding rules. Our tool supports RFC 3986 (URIs), HTML5 form encoding, and legacy encodings. Understanding which standard applies helps prevent encoding issues in your applications.