b2KIT

HTML to Pug Converter

Convert HTML markup to Pug (Jade) template syntax with proper indentation and attribute formatting.

Tested tool guide Tested browser tools Checked August 16, 2026

What HTML to Pug Converter does, with a checked example

HTML to Pug Converter rewrites an HTML fragment or document as Pug source. Element nesting becomes indentation, closing tags disappear, and HTML attributes are expressed in Pug's attribute notation. Text nodes stay with their corresponding elements, producing template source that can be edited or pasted into a Pug file. The most consequential surprise is that indentation is executable structure in Pug, not cosmetic formatting. Preserve the leading spaces when copying the result, and inspect whitespace-sensitive content before using it.

Worked example

A concrete input and expected output from the current implementation.

Input

<section>
  <h1>Notes</h1>
  <p>Two items</p>
</section>

Expected output

section
  h1 Notes
  p Two items

The section becomes the outer Pug tag. Its h1 and p children are indented one level, and their short text nodes follow their tag names on the same lines.

How the result is produced

1

Nesting becomes indentation

Each HTML element produces a Pug tag line, while descendants are placed on deeper indented lines. Because Pug derives parent-child relationships from indentation, HTML end tags have no direct counterpart in the converted result. Sibling elements remain at the same indentation level, as the h1 and p do in the example.

2

Markup becomes Pug notation

Tag content and attributes are translated into Pug forms instead of being preserved as angle-bracket markup. Simple text can follow its tag on the same line. IDs, classes, and other attributes can use Pug shorthand or parenthesized attribute notation. The returned value is editable Pug template source, not rendered HTML or a browser preview.

Good uses

  • Turn a static HTML page section into a starting Pug view while migrating an existing site to Pug templates.
  • Convert copied component markup before inserting it into an Express application or another project whose views are written in Pug.
  • Translate a small HTML reproduction when comparing explicit opening and closing tags with Pug's indentation-based representation of the same element tree.

Limits and checks

  • Equivalent structure does not always guarantee identical rendered spacing. Review boundaries between inline elements and text, where a missing or added space can affect the visible sentence.
  • Inspect pre, textarea, script, and style content carefully. Their text and line breaks may need Pug-specific handling beyond an ordinary nested-tag conversion.
  • The converter changes syntax but does not infer Pug variables, loops, conditionals, includes, inheritance, or mixins merely because the HTML contains repeated or similar structures.

Common questions

Will the converted Pug render exactly the same HTML?

Often, straightforward elements, attributes, and text preserve the intended structure. Exact output is not guaranteed for every fragment, especially when rendering depends on whitespace, unusual attribute values, embedded code, or another template language mixed into the HTML. Compare the rendered result when exact markup or spacing matters.

Why are the HTML closing tags absent from the output?

Pug uses indentation to mark containment, so a closing tag would be redundant. An indented line belongs to the nearest less-indented tag above it, while returning to an earlier indentation level ends that element's child block. Changing indentation after conversion can therefore change the resulting document structure.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools