HTML to YAML Converter
CV-62Paste HTML and get its structure as YAML. Each element has a tag, its attributes and its children, with text as plain strings.
Runs in your browser. Nothing is uploaded.
HTML
YAML
How to use it
- Paste your HTML into the input box, or open an .html file and drop it on the box.
- Pick a 2 or 4 space indent.
- Turn on Keep comments if you want them in the tree.
- Copy the YAML or download it as a .yaml file.
The shape of the YAML
The result is a list with one entry per top-level node. An element has the key tag, then attributes as a mapping if it has any, then children as a list if it has any. Text sits in the children list as a plain string. A doctype becomes an entry with the key doctype. Repeated attributes keep the first value, and an attribute without a value becomes an empty string. This is a description of the document tree, not a format that browsers read.
How text and whitespace are handled
Text is trimmed and runs of whitespace are collapsed to single spaces. Text that is only whitespace is dropped. That means the exact spacing between a word and an inline tag, such as the space before a link, is not kept in the YAML. Entities like & are decoded. Script and style content is kept as a text value. Comments are dropped unless you turn on the option.
Limits of the parser
The HTML is read by a small tolerant tokenizer. It closes void tags like br and img, and common optional end tags such as li and td, but it is not a full HTML5 parser, so badly broken markup may nest differently than a browser would. The YAML text is produced by the js-yaml library, which loads the first time you use the tool.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
No HTML found to convert. | The input is empty, or holds only comments and whitespace that were dropped. | Paste some HTML, or turn on Keep comments if the input is only a comment. |
Questions people ask
How do I convert HTML to YAML?
Paste the HTML and the YAML appears on the right. Each element becomes a mapping with tag, attributes and children keys. Choose the indent and copy or download the result.
Can I turn the YAML back into HTML?
Not with this tool. The YAML describes the tree, but it trims whitespace and drops comments by default, so it is meant for reading, diffing and processing, not for round trips.
Why is the space before my link gone?
Text is collapsed and trimmed per piece, so the spaces at the edges of a text node are removed. The words are all there; only the edge whitespace around inline tags is lost.
Are attributes kept in their original order?
Yes, in the order they appear in the tag. If an attribute is repeated, the first one wins, which is how browsers treat it. The result updates as soon as you change the input or an option.
Does it work for a full HTML page?
Yes. The doctype, html, head and body elements all become entries in the tree, including the contents of script and style as text. You can try it with the sample first to see the output.
About this tool
The result is a YAML list with one entry per top-level node. An element has the key tag, then attributes (a mapping) when it has any, then children (a list) when it has any. Text is a plain string in children. Text is collapsed to single spaces and trimmed, and text that is only whitespace is dropped, so the exact spacing between text and inline tags is not kept. An attribute with no value becomes an empty string, and a repeated attribute keeps its first value. Comments are dropped unless you keep them, and a doctype becomes a doctype entry. Script and style content is kept as text, and entities are decoded. The HTML is read with a built-in tokenizer that closes void tags and common optional end tags, but it is not a full HTML5 parser. YAML is written with the js-yaml library, loaded the first time you convert.