HTML to YAML Converter
Paste HTML and instantly convert the DOM structure to a clean YAML representation
Paste any HTML markup and get a structured YAML tree showing every tag, attribute, and text node — no manual rewriting of nested elements into indented keys. The browser’s own DOM parser does the heavy lifting, so malformed tags get handled the same way a real browser would read them. And everything runs in your browser. Nothing gets uploaded.
How It Works
The browser’s native DOMParser reads your HTML and builds the same tree structure a browser uses internally. The converter then walks every node — element, text, comment — and translates it into YAML mappings. Each element gets a tag key, an attributes map, optional text, and a children list. Compact mode strips fields that are empty so you only see what matters.
Examples
Simple Navigation Bar
Converting a basic nav element with links into a YAML tree.
<nav class="main-nav">
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
tag: nav
attributes:
class: main-nav
children:
- tag: a
attributes:
href: /
text: Home
- tag: a
attributes:
href: /about
text: About
Form with Input Fields
A login form — labels, inputs, and a button. Shows how attributes like type and placeholder map to YAML.
<form id="login">
<label for="email">Email</label>
<input type="email" id="email"
placeholder="[email protected]">
<button type="submit">Log In</button>
</form>
tag: form
attributes:
id: login
children:
- tag: label
attributes:
for: email
text: Email
- tag: input
attributes:
type: email
id: email
placeholder: [email protected]
- tag: button
attributes:
type: submit
text: Log In
Nested Table Structure
Tables have deep nesting — table > thead > tr > th — which is hard to read in raw HTML but maps cleanly to YAML’s indentation.
<table>
<thead>
<tr>
<th>Name</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Widget</td>
<td>$9.99</td>
</tr>
</tbody>
</table>
tag: table
children:
- tag: thead
children:
- tag: tr
children:
- tag: th
text: Name
- tag: th
text: Price
- tag: tbody
children:
- tag: tr
children:
- tag: td
text: Widget
- tag: td
text: "$9.99"
Who Uses This
Inspecting DOM structure of third-party pages or converting HTML snippets into config-friendly YAML for static site generators.
Extracting structured data from scraped HTML pages and piping the YAML into processing pipelines.
Documenting page layouts by converting HTML into readable YAML that non-developers can actually follow.
Learning how the DOM tree works by seeing HTML mapped to a clear parent-child hierarchy in YAML.
Common Mistakes
The converter doesn’t dump your HTML as-is. It parses the DOM and outputs the structure — tags, attributes, text — as YAML keys. If you want the literal HTML string in YAML, wrap it in quotes yourself.
Without compact mode, every single element shows attributes: {} and children: [] even when they’re empty. Turn on compact mode for cleaner output — you probably don’t need those blank fields.
The browser’s DOMParser wraps fragments in a full document structure automatically. If you paste <div>Hello</div>, the output may include html, head, and body wrappers. Paste only the snippet you care about, or look for your content under the body node in the output.
Technical Details
- Processing: 100% client-side — uses the browser’s native DOMParser API
- Browser Support: Chrome, Firefox, Safari, Edge
- Max Input Size: Limited only by your browser’s memory (tested with 500KB+ HTML files)
- Output Format: Standard YAML 1.2, 2-space or 4-space indentation
Frequently Asked Questions
Can I convert an entire webpage to YAML?
Yes, paste the full HTML source and the converter will walk the entire document tree. Keep in mind that large pages produce long YAML output. For big pages, compact mode helps cut the noise by removing empty attribute and children fields.
Does this preserve CSS styles or JavaScript?
Inline styles show up as an attribute value on the element (like style: "color: red"). CSS in <style> tags and JavaScript in <script> tags are captured as the text content of those elements. The converter doesn’t execute or interpret any scripts — it just records them as strings.
Is the YAML output valid and parseable?
Absolutely. The output follows YAML 1.2 spec and can be parsed by any standard YAML library — PyYAML, js-yaml, SnakeYAML, you name it. Special characters in text get properly quoted so nothing breaks the syntax.
What happens with HTML comments?
HTML comments are treated as comment nodes in the DOM. The converter picks them up and includes them in the YAML tree with a #comment type indicator. If you don’t want comments in the output, just remove them from your HTML before converting.
Can I convert YAML back to HTML?
Not with this specific tool — it’s a one-way conversion. The YAML to HTML direction would need a separate converter that reads the tree structure and rebuilds markup. Check the related tools section below for a YAML to JSON converter and other format tools.