HTML Formatter
Beautify and indent HTML markup.
OpenTurn a block of HTML into a nested JSON structure of tags, attributes and children.
Add a fragment; minified markup gives the cleanest output.
DOMParser builds the tree, fixing nesting the way browsers do.
Each element becomes { tag, attrs, children } starting at body.
Copy the JSON or download it for your tests.
You are writing a test that asserts on rendered markup, or feeding a page fragment into a script that prefers data to strings. Converting the HTML to a JSON tree gives you something you can walk with plain object access.
The converter parses your markup with DOMParser and serializes the body element recursively. Every element becomes an object with three fields: tag (the lowercase tag name), attrs (attribute names mapped to values) and children (an array). Text nodes are included in children as plain strings in document order, so mixed content like <p>Hi <b>there</b></p> keeps its sequence. Comments are skipped. The JSON is indented with two spaces and downloads as dom.json.
Whitespace between tags counts as text, so indented source produces strings such as "\n " among the children. Minify the markup first, or filter out whitespace-only strings in your code. The top-level object is always the body element, and anything the parser places in head (title, meta, link) is not included. To read the result comfortably, open it in the collapsible JSON viewer. For a quick visual outline rather than data, use the DOM Visualizer, and to export only certain elements, filter them first with the Element Extractor.
The conversion runs on an inert document in your browser, with no scripts executed and no request sent.
Keyboard shortcut
Answers for this tool. For site-wide help, open the FAQ hub.
Not with this tool. The structure is simple enough to rebuild with a short recursive function: write the tag and its attrs, then each child in order.
Yes. They appear in attrs with an empty string as the value, which is how the DOM reports them.
Serialization starts at body. Elements the parser assigns to head, including title, meta and link, sit outside that tree.