HTML to JavaScript Converter

Form for HTML converting

This form allows you convert HTML to JavaScript variable or using write, writeln statements:


Your result can be seen below.

Result of HTML conversion to JS code


Move to "Paste Code" for Save it

About HTML conversion to JS Code

About HTML conversion to JavaScript

The HTML to JS Converter was created for online converting HTML into JS code. This can come in handy for print HTML code via JavaScript print functions or set into variable, used in most JS frameworks like node.js, react.js, angular.js, etc. Very useful in applications where the code must be dynamically generated. Quote and backslash characters will be appropriately escaped with backslashes so the strings will print correctly.

How it Works?

Just paste your HTML code to the textarea above and click to the button "Convert" and you will get Javascript statements or variable in the next textarea.

Example of HTML conversion to JS

Before:
<html>
    <head>
    <title>Your Title Here</title>
    </head>

    <body bgcolor="FFFFFF">
        <center><img src="wtools.jpg" align="bottom"> </center>
        <hr>
        <a href="http://wtools.io">Best Online Web Tools</a>is a link to another nifty site
        <h1>This is a Header</h1>
        <h2>This is a Medium Header</h2>
        Send me mail at <a href="mailto:[email protected]">[email protected]</a>.
        <p> This is a new paragraph!</p>
        <p> <b>This is a new paragraph!</b></p>
        <br> <b><i>This is a new sentence without a paragraph break, in bold italics.</i></b>
        <hr>
    </body>
</html>
After:
document.writeln('<html>');
document.writeln('    <head>');
document.writeln('    <title>Your Title Here</title>');
document.writeln('    </head>');
document.writeln('');
document.writeln('    <body bgcolor="FFFFFF">');
document.writeln('        <center><img src="wtools.jpg" align="bottom"> </center>');
document.writeln('        <hr>');
document.writeln('        <a href="http://wtools.io">Best Online Web Tools</a>is a link to another nifty site');
document.writeln('        <h1>This is a Header</h1>');
document.writeln('        <h2>This is a Medium Header</h2>');
document.writeln('        Send me mail at <a href="mailto:[email protected]">[email protected]</a>.');
document.writeln('        <p> This is a new paragraph!</p>');
document.writeln('        <p> <b>This is a new paragraph!</b></p>');
document.writeln('        <br> <b><i>This is a new sentence without a paragraph break, in bold italics.</i></b>');
document.writeln('        <hr>');
document.writeln('    </body>');
document.writeln('</html>');
Or:
var variable = '' +
'<html>' +
'    <head>' +
'    <title>Your Title Here</title>' +
'    </head>' +
'' +
'    <body bgcolor="FFFFFF">' +
'        <center><img src="wtools.jpg" align="bottom"> </center>' +
'        <hr>' +
'        <a href="http://wtools.io">Best Online Web Tools</a>is a link to another nifty site' +
'        <h1>This is a Header</h1>' +
'        <h2>This is a Medium Header</h2>' +
'        Send me mail at <a href="mailto:[email protected]">[email protected]</a>.' +
'        <p> This is a new paragraph!</p>' +
'        <p> <b>This is a new paragraph!</b></p>' +
'        <br> <b><i>This is a new sentence without a paragraph break, in bold italics.</i></b>' +
'        <hr>' +
'    </body>' +
'</html>' +
'';
After the conversion, you can apply the JS Code to your project or use it for some other purpose.
Donate

Did you like this tool? You can donate to us. This will help us improve our free web tools.

Paypal