HTML and JS String Converter
WebEverything runs locally in your browser — nothing is uploaded
One direction puts HTML into JS as a string literal: newlines, quotes and backslashes escaped, optionally wrapped as `const html = …` or `document.write(…)`. The other direction turns an escaped string copied out of code back into readable HTML. The dangerous case is `</script>`: if that JS lives inside a `<script>` tag, a `</script>` inside the string closes the tag early — the rest becomes visible text on the page, and the console may stay silent. So it is broken into `<\/` by default, and inside a JS string those two are the same value, so nothing changes.
Features
- Both directions: HTML → JS string and JS string → HTML
- Direction detected from the input (`<` means HTML, a quote means a JS string), or set it yourself
- Breaks `</` into `<\/` by default, preventing a premature `</script>`
- Three quote styles: single, double and backtick (backtick also escapes `${` and backticks)
- Three output shapes: the bare string, `const html = …`, or `document.write(…)`
- Escapes newlines, tabs, backslashes and the line separators U+2028 / U+2029
- Unescaping understands `\n` `\t` `\xHH` `\uHHHH` `\u{…}` and line continuations
- Unknown escapes keep their backslash — you may have pasted a regex
How to use
- Paste HTML, or a quoted JS string
- Leave Direction on Detect, or choose one
- Pick the quote style and output shape; the result updates live
- Copy the result — it is ready to paste into code
FAQ
- Why turn </ into <\/?
- Because inside a `<script>` tag the HTML parser only looks for the character sequence `</script` in the source — it does not care whether it sits inside a JS string. So any embedded HTML containing `</script>` closes the tag right there: the remaining JS becomes text on the page and the error message points somewhere unrelated. In a JS string `\/` and `/` are the same value, so breaking it changes no output — the only way to alter the source without altering the value.
- Single quotes or double quotes?
- It depends on the content. HTML attributes normally use double quotes (`class="btn"`), so putting HTML inside a single-quoted string needs far fewer escapes and reads better, which is why single is the default. Backticks (template literals) look cleanest, but cost extra escapes for `${` (otherwise interpolated) and for backticks themselves.
- How is the direction detected?
- By one test: does the input start with `<` once trimmed? That means it is markup. The reverse test — does this look like an escaped JS string — is far too weak, since almost any text can look like one, and guessing wrong means unescaping your prose as if it were code (a literal `\n` becomes a real newline) in a way that is invisible afterwards. So only one side is detected; pick the other by hand.
- Why are some escapes left alone?
- Unescaping only handles escapes with a defined meaning in JS: `\n` `\t` `\b` `\f` `\v` `\0`, `\xHH`, `\uHHHH`, `\u{…}`, and the quote and backslash characters themselves. Anything else (`\d`, `\q`) keeps its backslash rather than dropping it — you may have pasted a regex, and dropping the backslash turns `\d` into `d`, which means something else entirely.
Related tools
HTML Entities
EncodingTurn < > & and quotes into HTML entities and decode them back in a single pass, so &lt; becomes <, not an angle bracket. Runs in your browser.
Unicode Escape
EncodingConvert non-ASCII text and emoji into \uXXXX or \xXX escapes and back, with emoji written as proper surrogate pairs. Runs entirely in your browser.
cURL Toolbox (code / parse / build)
WebTurn a curl command into seven languages of code, or break it into method, headers and body fields; or build a curl command back from an HTTP request.
URL Parser
WebParse a URL into scheme, host, port, path, query parameters and fragment, with each parameter shown raw and decoded. Runs entirely in your browser.
User-Agent Parser
WebParse a user agent into browser, version, OS, device type and engine, and see which rules matched. Pattern matching only. Runs entirely in your browser.
HTTP Status Codes
WebLook up an HTTP status code for its meaning, 1xx–5xx class, typical uses and common traps. Runs entirely in your browser.