are escaped locally.","url":"https://voritools.com/htmloutjs/","applicationCategory":"DeveloperApplication","operatingSystem":"Any","inLanguage":"en","isAccessibleForFree":true,"offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"browserRequirements":"Requires a modern browser with JavaScript enabled"}

How to convert between HTML and document.writeln()

The box works in both directions. HTML to JS wraps every line of the pasted markup in a document.writeln("...") statement that can be dropped into a script block; JS to HTML reads those statements back and returns the text they would print.

The conversion runs in the page with browser JavaScript. The input is treated as text - it is never executed - and nothing is uploaded, so internal markup can stay on your machine.

  1. Paste HTML and press HTML to JS. Each input line becomes one document.writeln("...") statement; quotes, backslashes and </script> inside the markup are escaped so the result survives a script block.
  2. Paste JavaScript that contains document.writeln("...") calls and press JS to HTML. Recognized calls are replaced by the text they would print; anything else in the paste is left untouched.
  3. Use Copy to put the result on the clipboard. Clear empties the box and hides the result panel.
  4. Check the output before shipping it. The tool escapes the wrapper and splits lines; it does not minify, reformat or validate the HTML itself.

What the conversion changes, and what it leaves alone

Escaping in the generated statements

A backslash becomes \\, a double quote becomes \" and the sequence </script> is written <\/script> so it cannot end the surrounding script element. The line separators U+2028 and U+2029 are escaped the way a JavaScript engine expects.

Everything else is kept as typed: single quotes, tabs, accented letters and emoji stay as they are, so save the embedding page as UTF-8.

Reading existing calls back into HTML

The reverse direction recognizes document.writeln("...") and document.writeln('...') with the usual escapes (quotes, backslashes, \n, \t, \uXXXX and similar) and replaces each call with the text it would print.

It is a reader, not a JavaScript engine: code is never executed, and constructs it does not recognize - document.write without ln, template literals, or calls built from variables - pass through unchanged.

Where this fits

Typical uses: reviving markup from an old page that wrote HTML through document.writeln, preparing a snippet that has to sit inside a <script> block, or checking what a generated call would actually output.

If you need a JavaScript string array instead of writeln calls, use the sibling HTML to JavaScript tool; it covers the array format and plain string literals.

Recent tools: