Codec lesson · URL Percent

URL Percent: encode UTF-8 octets for a URI component

RFC 3986 percent encoding writes an octet as % followed by two hexadecimal digits. Encode Keyboard leaves only unreserved URI characters literal and encodes everything else byte by byte.

Standard · RFC 3986 Round trip: Exact for the Encode Keyboard canonical RFC 3986 profile and valid UTF-8 text.
Learning objective

Identify RFC 3986 unreserved characters, encode UTF-8 bytes with uppercase %HH triplets, and avoid form-style + handling.

Letters, digits, -, ., _, and ~ remain literal. Every other UTF-8 byte becomes an uppercase %HH triplet. Spaces therefore become %20, never + in this profile.

01

How Encode Keyboard handles it

1

Convert text to UTF-8 octets

Non-ASCII characters may produce several bytes and therefore several %HH triplets.

2

Leave unreserved characters alone

Only ALPHA, DIGIT, -, ., _, and ~ remain literal.

3

Validate a canonical meaning

Decode accepts upper- or lowercase hex in complete triplets, normalizes it to uppercase, and rejects raw reserved characters or invalid UTF-8 bytes.

02

Worked example

InputXin chào
OutputXin%20ch%C3%A0o

The space is %20; à is UTF-8 bytes C3 A0 and therefore becomes %C3%A0.

03

Good uses

  • Learning how URI component bytes are represented
  • Inspecting percent-encoded UTF-8 text
  • Preparing non-sensitive text for a documented URI-component context
04

Validation and common errors

  • The encoder writes uppercase %HH; the decoder also accepts lowercase hex in complete triplets
  • Encode a literal % as %25 and a space as %20
  • Do not use + as an alias for a space in this RFC 3986 profile
05

Practice in your browser

This uses the same documented rules as the app and runs only in this tab.

URL PercentThis uses the same documented rules as the app and runs only in this tab.
Result

This uses the same documented rules as the app and runs only in this tab.

06

Knowledge check

How does this RFC 3986 profile encode a space?