Escape a URL for code
Pasting a URL into source code is where & starts a background job, % eats the next two characters, and a stray quote ends the string early. Paste the URL once and get a correctly quoted literal for every language you are likely to need, each with its own copy button.
How to use
- Paste the URL into the input. The table fills in as you type.
- Find your language in the left column.
- Click Copy on that row — you get the complete literal, quotes included, ready to paste into code.
- Note that some rows deliberately use a different quoting style than you might expect:
@"…"for C# and backticks for Go, because those forms need no backslash escaping at all and so cannot be got wrong.
The three that bite most often
bash and sh. Double quotes are not enough: $, backtick and \ stay live inside them, so a URL with $ in a parameter gets silently substituted with an empty variable. Single quotes are literal, and the only character needing care is the single quote itself, which is why the output uses the '\'' idiom. An unquoted URL containing & is worse — the shell splits the command there and backgrounds the first half.
cmd.exe. A lone % is a variable marker, so %20 can vanish or be replaced. The literal form doubles it to %%.
YAML. A bare URL is usually fine, but one starting with * or & reads as an alias or anchor, and anything with : in it reads as a nested key. Single-quoted output avoids the whole class of problem.
FAQ
Does this percent-encode the URL as well?
No, and that is deliberate. This tool changes how the URL is quoted for a programming language, not how it is encoded for the web — the URL itself comes out byte-identical. If you also need percent-encoding, run the URL through the URL encode / decode tool first, then paste the result here.
Why is the regex row escaped so heavily?
Because a URL is full of regex metacharacters: ., ?, +, *, (, ), [, ], /. The row escapes all of them so the pattern matches your URL literally rather than treating it as a pattern.
Is the Java row safe for very old versions?
Yes — it only escapes backslash and double quote, which is all the Java string grammar requires. Kotlin uses the same rules.
What about a URL inside a JSON file?
Use the JSON value row. It is the same output as the JavaScript row, since JSON string syntax is a subset of JavaScript's — including the forward-slash question, where escaping / as \/ is legal but never required.