cv.cm
All lessons

Developer tools

How to encode a URL

You have a string that must travel inside a URL. You will encode or decode it in this tab. Encoding the whole address also encodes the slashes. A query that uses + for a space decodes that plus as a space.

6-minute read

Today's result A percent-encoded string, or the text decoded from one, including spaces that arrived as +.

Open URL encode when the string is in front of you. Encode uses encodeURIComponent. Decode turns + into a space before reading % sequences. Nothing is uploaded.

Open URL encode
Contents
  1. Decide whether slashes must survive

    Encoding a query value is the usual job. Encoding https://cv.cm/a b also turns : and / into %3A and %2F. The result is one component, not an address you can open as-is.

    A space encodes as %20. A slash encodes as %2F. + decodes as a space.
    A space encodes as %20. A slash encodes as %2F. + decodes as a space.
  2. Open URL encode on cv.cm

    The string stays in this tab.

    Open URL encode
  3. Choose encode or decode

    Encode turns text into percent-encoding. Decode turns percent-encoding back into text. Encoding a string that is already encoded wraps it a second time.

  4. Watch the space

    Encode writes a space as %20, not as +. Decode turns both %20 and + into a space. a+b decodes as a b.

    % must have two hex digits. Encoding twice leaves the % signs in place.
    % must have two hex digits. Encoding twice leaves the % signs in place.
  5. A broken percent sequence fails

    Each % must be followed by two hex digits. %zz and a lone % fail. Fix the pairs, then decode again.

  6. Check one character you expect

    A space should come back as a space. A slash you encoded on purpose should come back as /. If the text is still full of % signs, it was encoded twice.

FAQ

Can I encode a URL free online?

Yes. cv.cm encodes and decodes the string in this tab. Nothing is uploaded.

What happens to a space?

Encode writes %20. Decode turns %20 and + into a space.

Will slashes stay if I encode a whole address?

No. : and / become %3A and %2F. Encode a query value when the address itself must stay openable.

Why did decode fail?

A % needs two hex digits after it. %zz and a lone % fail.

Is the string uploaded?

No. Closing the tab discards it.