HTML to string

Paste HTML to get it as a correctly escaped string you can paste into code.

This free HTML to string converter works in your browser. How the files you choose are handled is set out in the privacy policy.

Which form to choose

  • Template literal keeps line breaks and lets you insert values with ${}. Any ` and ${ in your HTML are escaped.
  • Concatenated strings work in old browsers and Java versions before 15.
  • Java text blocks and C# verbatim strings keep the HTML readable over several lines.
  • PHP nowdoc inserts no variables, so $ signs in the HTML are safe.

Safety

Building HTML from strings in code is fine for fixed templates. When you insert user input, escape it, or use the DOM (textContent) instead, to avoid cross-site scripting.

Questions

Does it work for other text, not just HTML?

Yes. Any text, such as SQL or JSON, can be turned into a string the same way.

Is my code uploaded?

No. Everything runs in your browser. What you type is not sent anywhere.

Last reviewed .

Related converters and guides