HTML to YAML Converter

Convert HTML markup into a YAML outline of its elements, attributes, and text. It is handy for extracting content, writing test fixtures, or reviewing a page's structure.

Updated
Runs in your browser. Your data is not uploaded.
Converts as you type for inputs up to 200 KB.

How to use the HTML to YAML Converter

  1. Paste markup into HTML input, or upload or drop an .html file.
  2. Pick the Indent for the YAML.
  3. Press Convert, then copy the YAML or download converted.yaml.

How it works

The markup is parsed by your browser's own HTML parser, the one it uses to show web pages, so unclosed tags and missing quotes are repaired the same way a browser would. Nothing is rendered and no scripts run.

  • A full document (with <html>) is converted from the html element. A fragment is converted from the elements you pasted.
  • Each element becomes a key with its tag name. Repeated sibling tags become a list.
  • Attributes become '@name' keys. Text is trimmed, and text next to child elements goes under '#text'.
  • Comments and whitespace between tags are dropped.

Examples

Input:

<nav class="menu">
  <a href="/">Home</a>
  <a href="/about">About</a>
</nav>

Output:

nav:
  '@class': menu
  a:
    - '@href': /
      '#text': Home
    - '@href': /about
      '#text': About

Limitations

  • Sibling elements of different types are grouped by tag name, so the original order between, say, <h2> and <p> is lost.
  • Inline formatting inside text, such as <b> in a sentence, becomes separate keys, which splits the sentence.
  • The contents of <script> and <style> are kept as plain text.
  • Files are limited to 5 MB.

Frequently asked questions

Does the HTML need to be valid?

No. The browser's parser fixes unclosed tags and other common mistakes before converting, just as it does when it displays a page.

Are scripts in my HTML run?

No. The markup is parsed into an inactive document that is never displayed, so scripts, images, and styles are not loaded or run.

Can I convert the YAML back to HTML?

Not exactly, because the order between different tags isn't kept. Use the YAML to XML converter to get XHTML-style markup back when order doesn't matter.

Is my HTML uploaded?

No. It is converted in your browser.

Often used together with the HTML to YAML Converter.