HTML to AST
Convert HTML to Pug templates, JSX for React, or a JSON syntax tree.
Paste your input on the left and press Translate (or Ctrl/Cmd + Enter) to get the result on the right. Free, no sign-up.
Example
<div class="card" id="profile">
<img src="/avatar.png" alt="Avatar">
<h2>Ada Lovelace</h2>
<p>First <strong>programmer</strong>.</p>
<a href="https://example.com" target="_blank">Website</a>
</div>[
{
"type": "tag",
"name": "div",
"voidElement": false,
"attrs": {
"class": "card",
"id": "profile"
},
"children": [
{
"type": "text",
"content": "\n "
},
{
"type": "tag",
"name": "img",
"voidElement": true,
"attrs": {
"src": "/avatar.png",
"alt": "Avatar"
},
"children": []
},
{
"type": "text",
"content": " "
},
{
"type": "tag",
"name": "h2",
"voidElement": false,
"attrs": {},
"children": [
{
"type": "text",
"content": "Ada Lovelace"
}
]
},
{
"type": "text",
"content": " "
},
{
"type": "tag",
"name": "p",
"voidElement": false,
"attrs": {},
"children": [
{
"type": "text",
"content": "First "
},
{
"type": "tag",
"name": "strong",
"voidElement": false,
"attrs": {},
"children": [
{
"type": "text",
"content": "programmer"
}
]
},
{
"type": "text",
"content": "."
}
]
},
{
"type": "text",
"content": " "
},
{
"type": "tag",
"name": "a",
"voidElement": false,
"attrs": {
"href": "https://example.com",
"target": "_blank"
},
"children": [
{
"type": "text",
"content": "Website"
}
]
},
{
"type": "text",
"content": " "
}
]
}
]Frequently asked questions
- Does the JSX output work in React?
- Yes. Attributes such as class and for become className and htmlFor, and inline styles become objects. Review event handlers and custom attributes by hand.
- Where does the conversion run?
- HTML to Pug and HTML to JSX are processed on the server and are not stored. HTML to AST runs in your browser.